Hello, I am brand new to this. I am trying to learn BASH scripting, and am trying the BASH excersise “two-fer”.
When I look at others’ solutions, they usually have something like: if [ -z "$1" ]; Where is the value of $1 coming from? How can input be provided if there is no command line to run the .sh from? I would normally do: two-fer.sh Alice on the command line to provide a value to $1.
Special Parameters from the manual is going to be where to find information about this.
It is the first argument passed to the command, used as input for your script.
Of course, you have already answered this with your “I would normally do:” example.
If you are having difficulty with an exercise, though, perhaps showing the code, answering what you expected to happen, but showing what is happening instead, can be helpful to understand what you are missing.
I did the following for the two-fer exercise. It runs perfectly locally, but fails all checks in the online editor. What am I doing wrong:?
read -p "What is the name?: " name
case $name in
("Do-yun") echo "\nOne for Do-yun, one for me" ;;
("Alice") echo "\nOne for Alice, one for me" ;;
("Bohdan") echo "\nOne for Bohdan, one for me" ;;
("Zaphod") echo "\nOne for Zaphod, one for me" ;;
("") echo "\nOne for you, one for me" ;;
esac
How do you paste into the online editor? I have been unable to do it.
I didn’t see that requirement anywhere. Where does it say that?
This is going to severely limit a beginner, since I don’t know much about using positional parameters.