

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


These simple exercises will help you practice what you learned in the first chapter of the Bash Beginner Series on Linux Handbook.
Write a shell script in that prints your user name. Difficulty level: Easy Hint: Use echo command with USER environment variable.
Write a shell script in that prints your current working directory. Difficulty level: Easy Hint: Use echo command with PWD environment variable.
Write a shell script in that prints the absolute path to your home directory. Difficulty level: Easy Hint: Use echo command with HOME environment variable.
Write a shell script in that prints the default shell. Difficulty level: Easy Hint: Use echo command with SHELL environment variable.
Write a shell script in that prints all of the above four questions, i.e. your user name, current working directory, home directory and default shell. Print all the answers in a separate line. Difficulty level: Easy To make things interesting, your output should be like this: Hello My name is XYZ My current location is XYZ My home directory is XYZ My default shell is XYZ You have to replace XYZ with actual values, of course.
Write a shell script in that prints your user name. #!/bin/bash echo "$USER" This $USER is one of the environment variable which is already set in almost all Linux distributions. Note that while the quotes are not important here, it is always a good practice to use double quotes with echo. More on the use of quotes can be found here.
Write a shell script in that prints your current working directory. #!/bin/bash echo "$PWD"
Write a shell script in that prints the absolute path to your home directory. #!/bin/bash echo "$HOME"
Write a shell script in that prints the default shell. #!/bin/bash echo "$SHELL"
Write a shell script in that prints all of the above four questions. #!/bin/bash echo "Hello" echo "My name is $USER" echo "My current location is $PWD" echo "My home directory is $HOME" echo "My default shell is $SHELL"