Please use ***[code][/code] tags
*** around your code and data, to preserve formatting and to improve readability. Please do not
use quote tags, colors, or other fancy formatting.
No, no, no! How many times must we stress it, NEVER
unless it's absolutely
necessary, there are truly no other options, and you know exactly at all times what the code is doing!
Eval command and security issues
Short form, if the command line that uses eval
has in it any variables or other substitutions that expand to unknown, uncontrolled values, then malicious or even accidentally damaging code can be run. Only if all
the values in the string and their resulting effects are known should you ever even consider it.
But it's a very rare case that you should need it anyway, as there are nearly always better alternatives.
The real problem in this case is that redirections and backgrounding are read at the beginning of the parsing order, before variable expansion happens; so trying to use a variable to set it will never work without the double parsing of eval.
way to implement this, however, would be to to create a function which tests the background condition first and then runs the command with the proper options in place.
case "$bg" in
0) mycommand "$@" ;;
1) mycommand "$@" & ;;
runmycommand "$background" option1 option2