I get confused about using command directly and using $(foo). I'm using Mac, I try to list apps which is install by brew cask
(a package manager), and echo each app. I have two short Shell scripts, first one like this:
#!/bin/bash
apps=$(brew cask list)
for app in ${apps}
do
echo "${app}"
done
It works fine, however another likes this:
#!/bin/bash
apps=$(brew cask list)
myecho=$(echo)
for app in ${apps}
do
${myecho} "${app}"
done
This one returns ./script2.sh: line 7: foo: command not found
, foo
is the name of app. What's the difference between I use echo directly and using myecho
as a aliases?
In this command
myecho=$(echo)
you are setting myecho
to an empty token. So the following command
${myecho} "${app}"
is simply "${app}"
, which is apparently "foo" (not what was intended). You would make an alias using different syntax:
alias myecho="echo"
Further reading:
$(
use)Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments