I'm trying to use eval command to eval a comment -- I'm not sure if this is the right way to do it. Example:
i=??
(What I want here is either a #
, to comment what's after, or blank)
somecommand arg1 arg2 $(eval $i) >> file
So based on the $i
value it has to be either:
somecommand arg1 arg2 # >> file
as of "Don't print to file"
or
somecommand arg1 arg2 >> file
as of "Print to file"
An example script for more clarity:
i=true
somecommand arg1 arg2 >> file1
[some code]
somecommand arg1 arg2 >> file2
[some code]
somecommand arg1 arg2 >> file3
[some code]
And so on...
I want it to print the output to the files only if $i
it true; or, as I tried at first, to eval
the $i to be a comment and comment the 'output to file' piece of code.
I asked because I think there is a more elegant way than doing something like this:
if $i
then
somecommand arg1 arg2 >> file3
else
somecommand arg1 arg2
fi
eval
is a last resort approach, especially for non-experts. So you should explain clearly why you think the linked answer is not suitable for you. – Hauke Laging Jul 18 '20 at 15:15somecommand
multiple times in your example, so this is same command , just writing to different files each time ? Orsomecommand
insomecommand arg1 arg2 >> file1
is different fromsomecommand
insomecommand arg1 arg2 >> file2
? – Sergiy Kolodyazhnyy Jul 18 '20 at 21:08