0

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?

1 Answer 1

1

; is the character for separating commands.

Try: ./script.sh 'a;b;c'

Sign up to request clarification or add additional context in comments.

3 Comments

Is there a work around for this? Can I not do without ' '?
I can only think of one other separator to use. For example :
Okay, I'll have to change the delimiter then.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.