by m463 · 6y ago · 0 comments
command \
--longopt1 \
--longopt2 arg \
argument
or command | \
command 2 | \
command 3 \
--opt1 \
--opt2 \
arg 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. command `# a comment` \
--longopt1 `# another comment` \
--longopt2 arg \
argument 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.
Otherwise, you'll get word splitting. E.g.,
cmd=(
test
"!= !="
!=
""
)
"${cmd[@]}" && echo Success
${cmd[@]} || echo FailureI'll add a comment or something explaining it but now I feel guilty and should probably go back and rewrite a few lines...
I mean—for long scripts I'll break them up but I haven't paid much mind to arguments/flags.
foo \
--group1 \
\
--group 2 \
--more-stuff 2 \
| \
bar \
--bar-stuff
using a line with a single backlash or breaking out the pipe can make grouping stuff clear. well, I mean as clear as having to use backslashes which to me is a little inelegant. Personally python and its indenting strategy has grown on me especially since editor support makes it painless to use and visually excellent.