I’m getting an error trying to write the output of a command into a variable, which is defined in a function.
chk()
hostsum=$(md5sum /etc/hosts | awk -F" " '{print $1}')
chk
It tells me about a syntax error:
./testchk.sh: Zeile 3: Syntaxfehler beim unerwarteten Wort
hostsum=$(md5sum /etc/hosts | awk -F" " '{print $1}')' ./testchk.sh:hostsum=$(md5sum /etc/hosts | awk -F” ” ‘{print $1}’)’
Zeile 3:
It works outer the function, but just won’t because of the function adding some extra quotes.
Any ideas except using it out of the function?
I think you just need to add braces:
Works fine for me here. The
bashman page says that a function has to contain a compound command, of which { list ; } is one example.