Passing variables from one script to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing variables from one script to another
# 1  
Old 02-29-2016
Computer Passing variables from one script to another

Hi,

this is the example i'm trying to do.

script1.sh

Code:
ABC="test.txt"
./script2.sh "$ABC"

script2.sh
Code:
INPUT="$HOMEDIR/$ABC"
echo $INPUT

when i run the 1st script it gives me
Code:
../home/

the test.txt is not passed into 2nd script. How can i resolve this.

Last edited by Don Cragun; 02-29-2016 at 06:40 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 02-29-2016
Did you export the variable?
And, the contents of ABC is available as $1 in script2.
# 3  
Old 02-29-2016
Thank you, your suggestion solved the problem Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing gnuplot variables to shell script

Hi, I need to pass a gnuplot value to a shell script. I have a main shell script (Main.sh) that has a bunch of gnuplot commands. Main.sh calls another gnuplot script (Child.gnu). A part of the code in Child.gnu is as follows: sp '</data/src/scripts/results/plot_data.sh $col' u (A):2:3 w pm3d... (8 Replies)
Discussion started by: annazpereira
8 Replies

2. Shell Programming and Scripting

passing a variables value from the called script to calling script using ksh

How do i get the value of the variable from the called script(script2) to the calling script(script1) in ksh ? I've given portion of the script here to explain the problem. Portion of Script 1 ============= ----- ----- tmp=`a.ksh p1 p2 p3` if then # error processing fi -----... (10 Replies)
Discussion started by: rajarkumar
10 Replies

3. Web Development

passing variables to python script

Hello again, You guys might remember me from the "Apache problems" thread. And because this forum is the only one that actually helped me out after months of problems I was hoping you could help me with something related. Now if you remember the final code that we made for creating an account... (0 Replies)
Discussion started by: darkphaux
0 Replies

4. Shell Programming and Scripting

Passing data from file to variables for script

Hello all! After searching through numerous helpful posts on these forums I am still having an issue with a task I am trying to accomplish. I am trying to take data from an input file, store the contents as variables, and use the variables in the script. The input file (input.txt) is... (2 Replies)
Discussion started by: screwed718
2 Replies

5. Shell Programming and Scripting

Need help passing variables in shell script to perl one-liner

I'm writing a script to automate some post-install tasks on RHEL4 servers. I need the following code to insert an 'A' in the middle of a string, then replace the string in a file. I know I can use sed to do this, but I'd like to use perl's in place edit so I don't have to write to a temp file,... (1 Reply)
Discussion started by: Xek
1 Replies

6. Shell Programming and Scripting

passing variables to sed function in a script ....

Hello , I have a script named testscript.sh wherein I have two variables $var and $final (both of which contain a number) I have a sed write function inside this script as follows: sed '1,2 w somefile.txt' fromfile.txt Now , in the above i want to pass $var and $final instead of... (2 Replies)
Discussion started by: shweta_d
2 Replies

7. Shell Programming and Scripting

passing two variables into a shell script?

Hello all, i have a infile.txt text file which contains such variables: aaa 123 asds 1323 asdsd 13434 lkjlkj 324324 23432 lkjlkj 24324 ljlkj 3j4lk 234kj3 and i want to pass them to my script such as: ./myscript $1 $2 where $1 is the first value in the first row and $2 is the second... (2 Replies)
Discussion started by: Bashar
2 Replies

8. Shell Programming and Scripting

passing variables to sed inside script

I am trying to pass a regular expression variable from a simple script to sed to remove entries from a text file e.g. a='aaaa bbbb cccc ...|...:' then executing sed from the script sed s'/"'$a"'//g <$FILE > $FILE"_"1 my output file is always the same as the input file !! any... (5 Replies)
Discussion started by: Daniel234
5 Replies

9. Shell Programming and Scripting

passing variables to awk from ksh script

I'm trying to write a ksh script that uses awk, but I want to pass variables to awk. For example (not working): if ];then searchstr=$1 lsof -i | awk '{if($9~/SEARCHSTR/) print $2} SEARCHSTR=$searchstr' else echo "usage: $0 <search string>" fi I tried several options. Is it... (3 Replies)
Discussion started by: rein
3 Replies

10. Shell Programming and Scripting

Passing filenames/variables into a script

Hi! I'm somewhat new to Unix (I use it to fiddle, but not seriously), and at my work I have come to use it quite a bit. My question is this: I want to create a script to take the tedium out of repetitious tasks. However, I need to pass a file name into the script in order for it to work. ... (5 Replies)
Discussion started by: MrToast
5 Replies
Login or Register to Ask a Question