I want to take inputs using commandline argument. The argument will be separated by a delimiter ';'. I wrote the following shell script for it:
arg=$1
echo "Input : $arg"
if [ arg != "" ]; then
echo "input(s) given...."
IFS=';' read -d '' -ra ADDR <<<"$arg"
echo "${ADDR[0]}"
echo "${ADDR[1]}"
echo "${ADDR[2]}"
for i in "${ADDR[@]}"; do
echo "$i"
done
fi
With the above, when I run as ./script.sh a;b;c the following is what is happening:
(Expected : ADDR[0] = a, ADDR[1] = b, addr[2] = c,) Output :
$ ./script.sh a;b;c
Input : a
input(s) given....
a
a
b: command not found
c: command not found
What am I doing wrong here? Clearly, $1 is not a;b;c but just a. How do I make it work according to my requirement?