Is it possible to invoke some program in a Bash script with complete command line parameters (both the key and the value) stored in variables?
I use the following scanimage
call in a script:
scanimage -p --mode "True Gray" --resolution 150 -l 0 -t 0 -x 210 -y 297 --format=png -o scan.png
I want to store some of the parameters in variables. I tried this, concerning the --mode
switch:
options="--mode \"True Gray\""
scanimage -p $options --resolution 150 -l 0 -t 0 -x 210 -y 297 --format=png -o scan.png
but this doesn't work, scanimage
says:
scanimage: setting of option --mode failed (Invalid argument)
Storing only the value for the --mode
switch does work:
mode="True Gray"
scanimage -p --mode "$mode" --resolution 150 -l 0 -t 0 -x 210 -y 297 --format=png -o scan.png
but I'd like to be variable about the switches, and I'd also like to customize multiple switches without knowing which will be set.
So is it possible to store not only the values for command line options in a variable, but also the option switch(es) along with the value(s)?
set -x
in your terminal and then try the command again and post the output. That will show us exactly what is being passed to thescanimage
command. I am guessing it will be'--mode' '"True' 'Gray"'
. – terdon Feb 17 '22 at 17:33+ scanimage -p --mode '"True' 'Gray"' ...
– Tobias Leupold Feb 17 '22 at 17:35