Reputation: 485
I have two shell scripts, i.e. (master, function); the master calls the function-script and tries to pass values to it.
Please note that function-script is an interactive script; i.e. it waits for user's answers to perform according to the answer.
So to pass one value I can write the following:
echo "string" | ./function-script
The problem is that I have to pass several values. Any advice?
Upvotes: 0
Views: 407
Reputation: 753805
Use command line arguments.
./function-script "string" "another string"
If you pre-empt standard input by piping data into the function script, you make interactive operation of the function script hard.
You could instead export the variables as environment variables, but just as global variables in regular programming are not a good idea because their use is hidden, so too with environment variables.
Upvotes: 0
Reputation: 246807
Can the "function-script" operate on positional parameters? If so, you'd call it like:
./function-script arg1 "argument 2" arg3
And then "function-script" would use "$1"
, "$2"
and "$3"
as required.
If "function-script" only takes input on stdin, do something like this:
printf "%s\n" arg1 "argument 2" arg3 | ./function-script
And "function-script" would do:
IFS= read -r arg1
IFS= read -r arg2
IFS= read -r arg3
Upvotes: 1
Reputation: 785156
Simple solution:
export a=1
syntax.Upvotes: 0