0

I am trying to set variables, so I can use them for evaluation in a while loop, in Bash.

while read l; do
  echo $l
  HASH=echo $l | awk '{print$1}'
  FILE_NAME=echo $l | awk '{print$2}'
  echo $HASH
  echo $FILE_NAME
done <$OLD_LOG_FILE

When I run it though, I get the following error:

./hash.sh: line 38: e5491a14c7374e7f2ee18e3095f8ac65: command not found
./hash.sh: line 39: e5491a14c7374e7f2ee18e3095f8ac65: command not found

Line 38 and 39 are lines where HASH and FILE_NAME are set.

I am using single quotes, and not do-quotes.

Should the HASH and FILE_NAME variables be set using a different method?

CS3000911
  • 131
  • 2
  • 2
  • 8
  • 3
    if you're only interested in the first and second fields, why not use your `read` command for that too and ditch `awk`? `while read -r hash file_name _; do echo "hash=$hash and file_name=$file_name"; done < "$old_log_file"`. By the way, what happens if there are spaces or funny characters in the file name? – gniourf_gniourf Sep 19 '15 at 14:56

1 Answers1

4

You want command substitution:

HASH=$(echo $l | awk '{print$1}')

What you're using is a special syntax for executing programs with pre-set environment variables:

var1=value progname args...

Hence bash is complaining that the value of $l is not a command which could be found.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176