coolerking
coolerking

Reputation: 521

Sending a parameter with space to another script in bash

I need to send a variable to another script (BASH) and uset after in this first script. The code goes something like this:

read var
source myscipt.sh $var
echo $var

The problem is that if y put spaces when entering $var after sending it to myscript.sh I only have the first one.

NOTE: In myscript.sh I only use $1 does this have something to do with the problem?

Thanx!!!

Upvotes: 0

Views: 70

Answers (1)

Stephane Rouberol
Stephane Rouberol

Reputation: 4384

You need to use quotes. Thus var will be considered as only one parameter, even if it contains spaces.

source myscipt.sh "$var"

Upvotes: 4

Related Questions