This question already has an answer here:

Ex. I have one script Test.sh

echo "/n read the value"
read info

if [ "$info" = 1 ];
echo "yes"
echo "no"

I want to call Test.sh script from another script (test2.sh) in nohup mode. Is there any way i can provide the value to "read info" by passing with arguments/ any other way.



marked as duplicate by sebasth, Anthony Geoghegan, terdon shell-script Sep 12 at 10:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Yes, by passing it on standard input. One way of doing that is a pipe (demonstrating how to reverse two lines):

$ cat > test.sh <<'EOF'
> #!/bin/sh
> read -r first
> read -r second
> printf '%s\n' "$second" "$first"
$ chmod u+x test.sh 
$ printf '%s\n' foo bar | nohup ./test.sh
nohup: appending output to 'nohup.out'
$ cat nohup.out 
  • & if we have multiple read command in the script then how can we provide the values ? – jazz Sep 11 at 10:03
  • Multiple lines. Each read will consume one "line", by default terminated with \n. See help read. – l0b0 Sep 11 at 10:07
  • I did't get it. My question is if 2 read commands in the script & i have to run in nohup mode then how can i give values using echo. Eg. script:#!/bin/sh echo "/n read the value1" read info1 echo "/n read the value2" read info2 echo "$info1 $info2">>log.txt – jazz Sep 12 at 7:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.