Intermediate · 6 missions
Bash scripting — Linux terminal practice
Write and run your own shell scripts with nano: variables, loops and if-tests.
Missions in this track
nano me apni script likho: variables, loops aur if conditions.
-
1
Variables
Store your name in a variable and print it:
name=Rahulthenecho "Hi $name".Show the command
name=Rahul; echo "Hi $name"No spaces around
=. Use$nameto read the value. -
2
Write a script
Open
~/hello.shin nano and writeecho "Hello $USER". Save with Ctrl+S, exit with Ctrl+X.Show the command
nano ~/hello.shScripts are just text files full of commands.
-
3
Make it executable
Give
~/hello.shexecute permission.Show the command
chmod +x ~/hello.shOr run it without the x bit:
bash hello.sh. -
4
Run your script
Run
~/hello.sh.Show the command
~/hello.shYou just wrote your first program. 🎉
-
5
Loops
Print the numbers 1 to 5 with a
forloop.Show the command
for i in $(seq 1 5); do echo $i; doneLoops automate boring, repeated work.
-
6
If tests
Print exists only if
~/hello.shis a file:[ -f ~/hello.sh ] && echo exists.Show the command
[ -f ~/hello.sh ] && echo exists-f file, -d folder, -e anything. Scripts use these tests to avoid errors.