-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SC2091
if $(which epstopdf)
then
echo "Found epstopdf"
fior
make_command() {
printf 'cat header %q footer > %q\n' "$1" "$2" | tee log
}
$(make_command foo.html output/foo.html)if which epstopdf
then
echo "Found epstopdf"
fior
make_command() {
printf 'cat header %q footer > %q\n' "$1" "$2" | tee log
}
eval "$(make_command foo.html output/foo.html)"ShellCheck has detected that you have a command that just consists of a command substitution. This often happens when you want to run a command (possibly from a variable name), without realizing that $(..) is for capturing and not for executing.
For example, if you have this shell function:
sayhello() { echo "hello world"; }
Then $(sayhello) will:
- Run
sayhello, capturing "hello world" - Run
hello world, resulting inbash: hello: command not found
Meanwhile, just sayhello will:
- Run
sayhello, outputting "hello world" to screen
Note that this is equally true if the command is in a variable, e.g. x=sayhello; $($x).
If you do have a command that outputs a second command, similar to how ssh-agent outputs export commands to run, then you should do this via eval. This way, quotes, pipes, redirections, semicolons, and other shell constructs will work as expected. Note that this kind of design is best avoided when possible, since correctly escaping all values can be difficult and error prone.
None.
- StackOverflow: Bash Function -> Command not found