Re:Use long flags when scripting (2013)
by inshadows on Friday September 18, 2020 @01:51PM
(#24519787)
It's nice but you cannot comment individual lines. For that you can go one step further and use arrays:
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.
[ Parent
| on HN ]
You can comment using a hack; check this out:
command `# a comment` \
--longopt1 `# another comment` \
--longopt2 arg \
argument
Re:Use long flags when scripting (2013)
by inshadows on Friday September 18, 2020 @03:47PM
(#24521147)
I 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.
Re:Use long flags when scripting (2013)
by lhoursquentin on Monday September 21, 2020 @06:12AM
(#24541641)
You should probably note that this hack spawns an additional shell process per comment :)
Re:Use long flags when scripting (2013)
by periodontal on Friday September 18, 2020 @02:12PM
(#24520035)
For bash, add quotes: "${cmd[@]}"
Otherwise, you'll get word splitting. E.g.,
cmd=(
test
"!= !="
!=
""
)
"${cmd[@]}" && echo Success
${cmd[@]} || echo Failure