So you want to create your very first bash script? Well it's actually pretty easy, just open your favorite text editor (vi, emacs, gedit, kate) and type:
#!/bin/bash echo "Hello World!"
Save this file under your /home directory (i.e /home/yourname), with the filename of firstscript.sh. You will then have to give the script execute permissions for yourself. In order to do this you will need to use the 'chmod' command:
[user@localhost ~]$ chmod 700 firstscript.sh
Now your script can now be executed:
[user@localhost ~]$ /home/yourname/firstscript.sh Hello World!
The She-Bang is the first line in this miniscript:
#!/bin/bash
This tells the shell to run this script using bash. Why do this? Well maybe you want to create a PHP script or a script for the 'awk' command. Without the she-bang, the shell won't know how to interpret the rest of the file.
The next line uses the 'echo command to "echo" text to the screen. Echo can be seen as a way to send text to the screen to keep the script user informed of what is going on in the shell. Using properly placed 'echo' statements can give the user valueable information as to what the script is currently doing as well as help the script's programmer in debugging the script itself.
Comments
Post new comment