by inshadows · 6y ago · 0 comments
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 Failure