Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
982 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use double quotes:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...