0

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!!!

1
  • Does myscipt.sh set var? When you source it, it runs in the same shell, and hence will modify the variables of the "parent" script. This is one of the reasons you should generally run scripts with ./myscript.sh rather than source Commented Sep 22, 2012 at 0:53

1 Answer 1

4

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

source myscipt.sh "$var"
Sign up to request clarification or add additional context in comments.

4 Comments

But I dont really care how many parameters myscipt.sh recieves, I want to know why after that it only have one!
without seeing your script I only can guess that it manages $1 only (not $2, $3,...)
Stephane... yes indeed, in myscript.sh I only use $1 but does this affect my main script? I am not changing the variables...
please ask an other question and give code samples to show the difficulty you meet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.