I write a bash script with a --verbose
option, where I want to write most lines before I execute them
xinput --set-prop "$TP" "Device Accel Constant Deceleration" $TOUCHPAD_DECELERATION
I would like to have exactly that output with quotes but the variables execuded, so the user can copy and paste that command to execute it again.
This would be the (more and more complicated, if there are a lot of quotes in the command) workaround with writing the line twice:
echo 'xinput --set-prop "'"$TP"'" "Device Accel Constant Deceleration" '"$TOUCHPAD_DECELERATION"
xinput --set-prop "$TP" "Device Accel Constant Deceleration" $TOUCHPAD_DECELERATION
How can I write the outcome ot this line with echo without having to write twice?
if [ $VERBOSE ];
So it is only printed out, if --verbose is called? – rubo77 Jul 04 '14 at 10:25set -x
within theif
block:if [ $VERBOSE ]; then set -x; fi
or, better,$VERBOSE && set -x
. – terdon Jul 04 '14 at 10:31set -x
at the top, then the whole script will be printed out while executed, which is far too much. Only some lines should be verbose, so stopping withset +x
is great, only a drawback, that it also prints out this last command:+ set +x
– rubo77 Jul 04 '14 at 10:54( $VERBOSE && set -x
and in the line after the last command a closing bracket)
– rubo77 Jul 04 '14 at 11:07