How to Run Shell Scripts ?
For creating a shell script, just open your vi editor or any other editor you are using to create files. In the editor type in the following two statements.
echo "Hello World!!"
echo "This is a shell script"
After typing in the statements, save the file with some filename say "abc".
There are two methods of running this shell script :
1. Use sh command on the shell prompt, like
$ sh abc
sh <shellscriptname> is used to execute the shell script passed to it as argument.
2. Other way is to change your shell script properties to executable. You can use chmod command on the shell prompt to change the properties of your shell script file to executable, such as :
$ chmod 755 abc
Where, chmod is the command which changes the properties of a file. 7 means you are giving read+write+executable permissions to the owner of the file i.e. you. 5 means you are giving read+write permissions to the group owners of the file. Next 5 means you are giving read+write permissions to other users. After using this command, your file i.e. shell script is now executable i.e. we can just type in its name on the shell prompt and it will gets executed, like :
and , just after giving this command, the statements stored in the abc file will gets executed on your shell prompt.
Re: How to Run Shell Scripts ?
Once a shell script is created, there are several ways to execute it. However, before any Korn shell script be can executed, it must be assigned the proper permissions. The chmod command changes permissions on individual files, in this case giving execute permission to the simple file:
$ chmod +x simple
After that, you can execute the script by specifying the filename as an argument to the ksh command:
$ ksh simple
You can also execute scripts by just typing its name alone. However, for that method to work, the directory containing the script must be defined in your PATH variable. When looking at your .profile earlier in the course, you may have noticed that the PATH=$PATH:$HOME definition was already in place. This enables you to run scripts located in your home directory ($HOME) without using the ksh command. For instance, because of that pre-defined PATH variable, the simple script can be run from the command line like this:
|Tags: linux, run, shell|
|Thread Tools||Search this Thread|
|Similar Threads for: "How to Run Shell Scripts ?"|
|Thread||Thread Starter||Forum||Replies||Last Post|
|Disable facebook scripts||Santiaago||Technology & Internet||5||01-04-2010 12:34 PM|
|How to edit and compile shell scripts||NetworkeR||Software Development||4||23-12-2009 01:09 PM|
|Why some scripts start with #||New buDDy||Operating Systems||3||14-10-2009 09:44 PM|
|Scripts are usually safe. Do you want to allow scripts to run ?||Ebadaah||Technology & Internet||4||02-07-2009 12:10 PM|
|Scripts not running in crontab||Frasier||Operating Systems||6||22-10-2008 01:33 PM|