Bashscript making a variable equal a command. error command not found

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

#!/bin/bash $CMD='md5sum ../Desktop/cases/CourseworkCase/Evidence/image.dd' echo $CMD

UPDATE

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 $CMD

Explanation

  1. 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"
  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))
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like