Example 1: Hello Shell Scripting
To write a simple shell script to print “Hello Shell Scripting” in the terminal.
Steps:
Create a shell-scripts folder inside workspace folder in your home folder. This is just to keep all your project files organized.
mkdir -p ~/workspace/shell-scriptsGo inside the shell-scripts folder.
cd ~/workspace/shell-scriptsInside this folder create a file called hello.sh.
touch hello.shOpen this file in a text-editor
gedit hello.shIf you have Sublime-Text installed, you can use-
subl hello.shNow write the shebang for the script.
#!/bin/bashBelow it write the command to print “Hello Shell Scripting” in the terminal.
echo Hello WorldNow save the file and close the text-editor.
Use chmod to make this script an executable.
sudo chmod +x hello.shRun the script.
./hello.shIf done correctly you should see the following output in the terminal-
Hello Shell ScriptingCode
#!/bin/bash echo Hello World