Ok here it goes. Imagine you have a script called repeater that takes a user input and gives it back (not very useful but easy to test with).
Here is my script.
#!/bin/bash
# Repeater
echo "Enter something for me to repeat"
read -e text
echo "You said: $text"
If you call the script, it prompts you for an input and then repeats what you said. For example
>>./repeater
Enter something for me to repeat
apple
You said: apple
Now here is the interesting part. We're going to call the script and provide the input, all with one command.
>> ./repeater << EOF
> apple
> EOF
If you want to put this in a script it could look like this
#!/bin/bash
./repeater << EOF
apple
EOF
./repeater << EOF
bannana
EOF
./repeater << EOF
kiwi
EOF
If your script requires multiple user inputs, put them on different lines, e.g.,
>> ./repeater_multiInputs << EOF
> input 1
> input 2
> input 3
> EOF
No comments:
Post a Comment