How to pass a variable from parent to child script.
Good Evening,
I want to create a bash script which will take some update from SVN and do some manipulations. I want to call that bash script from a wrapper bash script which will take few inputs from invoker like 'CustomerName' and 'BranchName' which needs to be passed to child bash script for actual manipulations and committing the changes back to SVN. I couldn't find a way to pass variables from parent to child bash script. I would be thankful if anybody can help. Code snippet of parent bash script is as follows; #!/bin/sh ## parent.sh echo Enter Your Name? read v_Name sh /home/test/child.sh > /tmp/child.log I need to retrieve value of v_name in child script |
What have you tried so far?
|
I have tried using export and it didn't work. I used 'source ./' but that is not what I require.
|
What's stopping you from passing the parameters as positional variables?
|
Without knowing anything about you child script it difficult to provide help. Did you write the child script?
Does the child script accept input data? If so how? There are many methods as suggested using command line arguments i.e positional parameters, prompting i.e. read statement, reading data from a file, reading data from stdin i.e. data from console/keyboard. |
I can pass positional variable as
Quote:
Quote:
Quote:
|
Pretty much the same works fine for me.....
Code:
[user@web105 ~]# cat parent.sh |
In addition,
$0 is how the script was called. $1 is the first command line argument. Since you redirect all output to a file you will not see output on the console. Have you check the child.log file? As TenTenths posted using "${v_Name}" will pass the name as one argument otherwise if there is a space in the name it will actually be parsed as two by the child. |
Quote:
|
Quote:
Code:
man tee |
As posted you can use the tee command
Code:
./child.sh "${v_Name}" | tee > /tmp/child.log |
All times are GMT -5. The time now is 07:42 AM. |