Here’s a simple Bash practice exercise to get you started:
Create a new Bash script called
greet.sh that prompts the user for their name and then prints a personalized greeting.
To do this, start by adding the “shebang” line to the top of your script:
Then, use the
read command to prompt the user for their name and store the result in a variable:
read -p "What is your name? " name
echo to print a personalized greeting that includes the user’s name:
echo "Hello, $name! Nice to meet you."
Save the script and make it executable using the
chmod +x greet.sh
Now, run the script by typing its name at the command prompt:
You should see the prompt asking for your name. Type your name and press enter, and the script should print a personalized greeting.
This is just a simple example, but there are many more things you can do with Bash, such as creating loops, branching logic, and working with files and directories. Try experimenting with different commands and syntax to see what you can do!
Add a Comment