Results 1 to 2 of 2

Thread: How to Run Shell Scripts ?

  1. #1
    Join Date
    May 2008
    Posts
    24

    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 :

    $ abc

    and , just after giving this command, the statements stored in the abc file will gets executed on your shell prompt.

  2. #2
    Join Date
    May 2008
    Posts
    11

    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:

    $ simple

Similar Threads

  1. Disable facebook scripts
    By Santiaago in forum Technology & Internet
    Replies: 5
    Last Post: 01-04-2010, 12:34 PM
  2. How to edit and compile shell scripts
    By NetworkeR in forum Software Development
    Replies: 4
    Last Post: 23-12-2009, 01:09 PM
  3. Why some scripts start with #
    By New buDDy in forum Operating Systems
    Replies: 3
    Last Post: 14-10-2009, 09:44 PM
  4. Scripts are usually safe. Do you want to allow scripts to run ?
    By Ebadaah in forum Technology & Internet
    Replies: 4
    Last Post: 02-07-2009, 12:10 PM
  5. Scripts not running in crontab
    By Frasier in forum Operating Systems
    Replies: 6
    Last Post: 22-10-2008, 01:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,427,266.67139 seconds with 17 queries