Your FIRST shell script...
Welcome, Guest.
"Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." -Benjamin Franklin

Author Topic: Your FIRST shell script...  (Read 2629 times)

Offline Spatry

  • Benevolent Dictator
  • Administrator - Sysop
  • **********
  • Posts: 5776
  • Cup of Linux Founder
    • Cup of Linux
Your FIRST shell script...
« on: April 29, 2016, 08:40:46 AM »
One of the most powerful features in Linux is the ability to create your own executable files. In Windows these are EXE, BAT or MSI. In Linux, ANYTHING can be made executable and today I will show you how to make a simple shell script, make it executable, then you can run it.

First we need to define an interpreter for the script. Since we are covering bash scripts in this section we will go with the usual shebang "#!/bin/bash" anything in your script which has been commented out will be ignored... these are lines starting with a #. Only the first line isn't ignored in that it defined the interpreter.
Code: [Select]
#This is my first script
echo "Hello world"
Using ANY text editor we type the preceding information into a new document and we save the file as "". We could name it anything we want but the ".sh" lets us know we can run it as a "shell" script. Now we need to make it executable...
Code: [Select]
chmod -x firstscript.shOnce the script is executable, you can run it with
Code: [Select]
Code: [Select]
sh firstscript.shand the output would be...
Code: [Select]
Hello worldJust about any commands you can enter into your shell can be made into a bash script. There are lots of reasons why you would want to make your own bash scripts and we will explore some of those reasons in this section of the forum.

Windows assumes the user is an idiot... Linux DEMANDS Proof!