0

I'm having difficulty passing a variable length string into bash script. I can echo the item from list


#!/bin/bash
echo $1 $2 $3
printf "\n"

args=("$@")

echo ${args[0]}
echo ${args[1]}
echo ${args[2]}
printf "\n"


if [ ${args[0]} = "foo test" ]; then
        echo "working"
        printf "\n"
else
        echo "not working"
        printf "\n"
fi



Command

./test.bash "foo test" foo2 foo3

Output

foo test foo2 foo3

foo test foo2 foo3

./test.bash: line 13: [: too many arguments not working

So I can echo the list element but when I try to use the list element to compare against a string it seems to unpack it. What am I doing wrong?

Thanks.

Eddie

Eddieturbo
  • 25
  • 4

0 Answers0