0

I want to send input from one script to another through shell scripts

when I stop this script it display the message do u want to continue

$MAIN_SCRIPT_PATH/first.sh stop

I am stopping the script using another script.I need to send yes to this script first.sh. How I will do this?

when stopping the first.sh it ask for user input. do you want to continue? I should send yes....

3
  • If it is just a small query, how about defining a bash function? – FelixJN Dec 13 '16 at 10:07
  • expect and send in shell script might work. – Mongrel Dec 13 '16 at 10:13
  • echo yes | $MAIN_SCRIPT_PATH/first.sh stop...whether this will work? – puspa Dec 13 '16 at 10:17
0

You could try writing to stdin of the script and see if that works. For example,

echo yes | $MAIN_SCRIPT_PATH/first.sh stop

Otherwise, there are programs like expect which allow you to wait for certain prompts before emulating user input.

Also, that's a poorly written script if it is asking for confirmation to stop without giving any additional options. See if first.sh --help displays any additional info around skipping the user input. There's typically a -y / -q / -s option to scripts which silence user input.

0

If your first.sh script is running and later you decide to pipe input to it, your question could be a possible duplicate from https://stackoverflow.com/questions/5374255/how-to-write-data-to-existing-processs-stdin-from-external-process

If you only need to pipe one time data to the first.sh script, perhaps this answers your question: https://stackoverflow.com/a/32643326/2019601

0

On linux, the coreutils package ships even the yes command. So you would run:

yes | $MAIN_SCRIPT_PATH/first.sh stop
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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