I\'m encountering an issue passing an argument to a command in a Bash script.
poc.sh:
#!/bin/bash
ARGS=\'\"hi there\" test\'
./swap ${ARGS}
<
Embedded quotes do not protect whitespace; they are treated literally. Use an array in bash
:
args=( "hi there" test)
./swap "${args[@]}"
In POSIX shell, you are stuck using eval
(which is why most shells support arrays).
args='"hi there" test'
eval "./swap $args"
As usual, be very sure you know the contents of $args
and understand how the resulting string will be parsed before using eval
.