i have shell script that require to do following things:
1) shell script need to store the logs to a log file.
2) shell script need to prompt user with a message and reads the input.
Example:
cat read-test.sh
echo -n "What is your name?"
read user_name
Executing this script:
./read-test.sh >> read-test.log
Expected User prompt:
What is your name?
rajiv
When i execute this script as
./read-test.sh
i get the desired output.
but when i execute this script as
./read-test.sh >> read-test.sh
“what is your name?” is saved to read-test.log file which i don’t want to.
Is there any way where i can show the user with message(“what is your name?”) and reads input?
The best answer depends on why you want to redirect like that, but one possible quick solution would be to change your
echoline like this: