1

I have a script: script

#!/bin/bash
read -n password
if [[ $password = $correct-password ]]; then
custom shell
else
exit
fi

Then, I have another script:

#!/bin/bash
echo password | ./script
commands

I want the commands in the second script to run in my custom shell not bash but they just run in bash. I can't do any changes in my first script. Instead of echo I have tried redirect password from file and here document "<<" still yeilds the same result.

2
  • It is a little unclear as to what you are asking ... Instead of echo password | ./script which just runs this script as a stand alone, you want to pass in arguments .. Is that what you are asking? Commented Sep 4, 2019 at 15:32
  • 1
    The if statement in the first script is not valid syntax. (( should be [[. Commented Sep 4, 2019 at 15:32

1 Answer 1

1

Use a here-doc, and put the password on the first line.

./script <<EOF
password
commands
EOF

When you use a pipe, the standard input of the script just comes from the pipe; anything after that line will be commands to the original shell once ./script exits.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.