Hi i keep getting the error

./imagehash.sh: line 2: =: command not found

When i know that i set the $CMD variable correctly (i tried the command outside the bash script and it worked just fine)

here's my bash script

 $CMD='md5sum ../Desktop/cases/CourseworkCase/Evidence/image.dd'
 echo $CMD


fixed the bash so theres no spaces in the $CMD variable and put '' around it but now i'm getting the error file no such file or directory i looked at the path and copied it letter for letter and its correct.

what am i doing wrong here?


Working example

CMD="$(md5sum ../Desktop/cases/CourseworkCase/Evidence/image.dd)"
echo $CMD


  1. To assign a variable never put a $ sign before nor spaces around the equal sign. The variable assignment in bash is like this:

  2. To create a variable with the output of a command you may use $(command). This will execute command and return its output.

  3. The output of md5sum will be like this:

    f110abe5b3cfd324c2e5128eb4733879 image.dd

    If do you want to isolate the md5 sum of the file name, you can use one of these lines instead:

    CMD="$(md5sum ../Desktop/cases/CourseworkCase/Evidence/image.dd | cut -d ' ' -f 1)"
    CMD=($(md5sum ../Desktop/cases/CourseworkCase/Evidence/image.dd))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.