In a script, I have:
CMD='/usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; '
MD5=$("${CMD}")
But the script gives the error:
-bash: /usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; : No such file or directory
However the contents of the $CMD work when typed verbatim at the command line, i.e.
/usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \;
Correctly generates a list of md5 hashes.
I've tried everything I can think of, including escaping the backslash and semicolon in the string, but can't seem to get it to work.
I've also tried invoking the command with backticks, which doesn't change the result.
What am I doing wrong ?
CMD=$(/usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; )
is the proper way of doing command substitution. If you are looking for the old way, they are not straight ticks, but backticks, like the one right under the~
character on most US type keyboards, but try using the method I suggested. It is the proper way of doing it. Backticks are being deprecated. – MelBurslan Mar 29 '16 at 14:05