Shell Script to pass arguments to another script
8,957
Calling script2.sh from script1.sh
#script1.sh
./script2.sh hello world
In script2.sh
var1 =$1
var2 =$2
echo $var1
echo $var2
Ouput will be hello world
Related videos on Youtube
Author by
Durga Swaroop
Updated on September 18, 2022Comments
-
Durga Swaroop over 1 year
I am new to the linux and shell scripting. I have a script, which has some read commands in it. So, something like
#script1.sh echo "something here" .... read var1 read var2 ...
Now, i want to write another script that calls this script and can pass the values to this script. So, i'm hoping for something like,
./script2.sh hello world
And, that would run script2 and store "hello" in var1 and "world" in var2. What should this script2 contain and how can i pass these arguments to script1?
I have searched for this a lot but i didn't find anyone explaining this.
-
DavidPostill over 8 yearsPlease start with a basic
bash
tutorial, for example Bash scripting Tutorial -
DavidPostill over 8 yearsFor the short answer see Sharing variables across multiple shell scripts
-