unfortunately I'm struggling with some kind of a "simple idea".
Within my Bash Script I'm checking a variable and if it's set I'll print output to the user (kind of verbose / show output).
[ ! -z $boolVerbose ] && fnc_print2user "i" "Print to user in one-line"
That's working pretty fine for me.
Now I have commands which don't allow suppressing their output, so I want to hide it or show it if my variable above is set/not empty.
I tried the following (and several other options..), to run the command as it is (means: showing output), expect the variable is not set/is empty, then it should append "&> /dev/null" to the command before (so suppress the output).
commandWithOutput $([ -z $boolVerbose ] && echo " &> /dev/null")
The script is running fine if I set my verbose Variable, but if it's not set my commandWithOutput throws an error that there're invalid arguments set (if I hard code to suppress every time it's working like charm).
Is it possible to do some kind of dynamic command adjustments like above in a one-liner or do I have to built real if-else statements with different commandWithOutput methods inside? Thanks in advance for your ideas & help! :-)
Aucun commentaire:
Enregistrer un commentaire