I'm facing some strange behabiour in my bash script.
I have a simple script parser.sh
, wich is really simple:
#!/bin/bash
for arg in "$@"
do
echo ARGUMENT: "$arg"
done
This script is called from another script in the same directory, lets call this one test.sh
#!/bin/bash
pwd
/parser.sh "ARG1=FIRST" "ARG2=TESTING SPACES"
The script shown above really works, and outputs the arguments as expected:
ARGUMENT: ARG1=FIRST
ARGUMENT: ARG2=TESTING SPACES
However, if I change the test.sh
as follows:
#!/bin/bash
ARGS=""ARG1=FIRST" "ARG2=TESTING SPACES""
pwd
/parser.sh $ARGS
This simple modification, makes the code to fails when iterating over arguments:
ARGUMENT: "ARG1=FIRST"
ARGUMENT: "ARG2=TESTING
ARGUMENT: SPACES"
Why is that happening? What am I missing?
Thanks in advance
man bash
. – choroba Jan 08 '21 at 13:02