Since we have learned basic commands in the Linux OS, we will now write our first shell script called hello.sh. You can use any editor of your choice, such as vi, gedit, nano, emacs, geany, and other similar editors. I prefer to use the vi editor:
- Create a new hello.sh file as follows:
#!/bin/bash # This is comment line echo "Hello World" ls date
- Save the newly created file.
The #!/bin/bash line is called the shebang line. The combination of the characters # and ! is called the magic sequence. The shell uses this to call the intended shell, such as /bin/bash in this case. This should always be the first line in a shell script.
The next few lines in the shell script are self-explanatory:
- Any line starting ...