Reputation: 11
I wrote such scripts in test.sh:
#!/bin/bash
CPPCHECK_PATH=haha
SRC_TMP_PATH=asdf
xmlPath=test
cmd="$CPPCHECK_PATH/cppcheck $SRC_TMP_PATH --xml 2>$xmlPath"
`$cmd`
I run "sh -x test.sh" and the console output is:
sh -x test.sh
+ CPPCHECK_PATH=haha
+ SRC_TMP_PATH=asdf
+ xmlPath=test
+ cmd='haha/cppcheck asdf --xml 2>test'
+ echo haha/cppcheck asdf --xml '2>test'
haha/cppcheck asdf --xml 2>test
++ haha/cppcheck asdf --xml '2>test'
why there is a pair of single quote around '2>test'?the script cannot run normally due to he single quotes. Anyone knows?
Upvotes: 1
Views: 184
Reputation: 799310
The single quotes are there to tell you that it is being used as an argument rather than a redirect followed by a filename, since you can't include redirects in a variable this way. Remove the redirection from the variable and perform it separately.
Upvotes: 2