Hi i keep getting the error
./imagehash.sh: line 2: =: command not foundWhen 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
#!/bin/bash $CMD='md5sum ../Desktop/cases/CourseworkCase/Evidence/image.dd' echo $CMDUPDATE
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?
1 Answer
Working example
#!/bin/bash
CMD="$(md5sum ../Desktop/cases/CourseworkCase/Evidence/image.dd)"
echo $CMDExplanation
To assign a variable never put a
$sign before nor spaces around the equal sign. The variable assignment in bash is like this:MYVAR="CONTENT"To create a variable with the output of a command you may use
$(command). This will executecommandand return its output.The output of
md5sumwill be like this:f110abe5b3cfd324c2e5128eb4733879 image.ddIf 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))