How come sh UsersInput.sh
gives a different output compared to bash UsersInput.sh
?
My script is below:
#!/bin/bash
echo -n "Enter: ";
read usersinput;
echo "You entered, "$usersinput"";
bash
localhost:Bash henry$ bash UsersInput.sh
Enter: input
You entered, "input"
sh
localhost:Bash henry$ sh UsersInput.sh
-n Enter:
input
You entered, "input"
How come -n
behaves properly with the first, but not with the second? What's the reason for this and is there a workaround?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…