erikbstack
erikbstack

Reputation: 13244

Using a variable containing spaces as a single argument

Think you have a variable that contains a string of text with spaces inbetween and you want to use that as input arguments for another script. How would you go about passing the variable content without worrying about the space chars?

The following doesn't work:

VAR1=hello\ world
#... do something else
./a_script.sh $VAR1

Upvotes: 1

Views: 211

Answers (1)

kev
kev

Reputation: 161604

Use double quotes:

VAR1=hello\ world
#... do something else
./a_script.sh "$VAR1"

Upvotes: 3

Related Questions