I have an example bash script, example.sh
that looks like this:
arg1=${1:-"one"}
arg2=${2:-"two"}
echo "Arg1: ${arg1}, Arg2: ${arg2}"
if I execute the command:
example.sh "sample text"
the terminal will print:
Arg1: sample text, Arg2: two
However if I store the command in an environment variable and execute it like so:
my_var='example.sh "sample text"'
$my_var
It will print:
Arg1: "sample, Arg2: text"
The issue is that the quotes are not blocking text into discrete arguments.
My question is what is the proper way to segment arguments when commands are being saved in environment variables? I’m open to changing the way that I execute the variable so long as I can save a command in an environment variable and execute it somehow.