0

Ex. I have one script Test.sh

#!/bin/sh
echo "/n read the value"
read info

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

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.

test2.sh

#!/bin/sh
Test.sh
Panki
  • 6,664
jazz
  • 27

1 Answers1

0

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"
> EOF
$ chmod u+x test.sh 
$ printf '%s\n' foo bar | nohup ./test.sh
nohup: appending output to 'nohup.out'
$ cat nohup.out 
bar
foo
l0b0
  • 51,350
  • & if we have multiple read command in the script then how can we provide the values ? – jazz Sep 11 '19 at 10:03
  • Multiple lines. Each read will consume one "line", by default terminated with \n. See help read. – l0b0 Sep 11 '19 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 '19 at 07:14