4 ms·
It's nice but you cannot comment individual lines. For that you can go one step further and use arrays: cmd=( command -x -y --bar OPTARG ARG
by inshadows 6y ago
It's nice but you cannot comment individual lines. For that you can go one step further and use arrays:
cmd=(
command
-x -y
--bar OPTARG
ARG ARG
)
$cmd
This works in Zsh. In Bash that would be ${cmd[@]} I think. I use this with long qemu command lines where I often modify and comment out arguments during testing.
- periodontal 6y agoFor bash, add quotes: "${cmd[@]}" Otherwise, you'll get word splitting. E.g., cmd=( test "!= !=" != "" ) "${cmd[@]}" && echo Success ${cmd[@]} || echo Failure
- tdons 6y agoYou can comment using a hack; check this out: command `# a comment` \ --longopt1 `# another comment` \ --longopt2 arg \ argument
- inshadows 6y agoI didn't mean commenting arguments for documentation but commenting them out while you're writing and testing the script. I.e. this won't work: command `# a comment` \ # --longopt1 \ --longopt2 arg \ argument AFAIK there's no hack for this. EDIT: Oh, `# a comment`. Didn't notice that. I'm going to explore it, thanks.
- lhoursquentin 6y agoYou should probably note that this hack spawns an additional shell process per comment :)