Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007
    Posts
    30

    Unanswered: Shell Script Confusion

    I'm kind of placed in a difficult situation. I'm currently working on an AIX in an RS6000 machine. I'm checking several scripts and have to create a new one.
    I checked the internet for basic on shell scripting and found several.

    They start with:

    #!/bin/sh

    or

    #!/bin/bash


    The scripts I'm looking at start with

    . /apps/intg/bin/env.sh

    others with

    . /apps/intg/bin/env.sh
    . /apps/intg/bin/scpprofile.sh


    So i'm confused now... in shell scripting in AIX how do I start. What is the difference with starting by # and starting with "."

    Thanks for any help.

  2. #2
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Hi,

    #!/bin/shell on the first line of a shell script is a directive for the parent shell to decide which interpreter to start. Without the directive the default shell interpreter will be used; so /bin/bash in Linux, /bin/sh (Bourne shell), /bin/ksh (Korn shell) or /bin/csh (C-shell) in most other flavours. (The shell executable can be placed on other locations to, like /usr/bin. Check this out on your system with 'which ksh' for instance).
    If, like in all systems I know, there's more then one kind of shell available it only matters which interpreter will be used if the shell script contains statements or structures that are shell dependent and not available in the default shell. (That's why it's not recommended to write shell scripts for a C-shell; it has a distinct syntax in many cases and csh is seldom the default shell.)
    So although it's not necesary it's a good practice to use the directive, if alone because the 'file' command can identify the files as shell scripts by that.

    The dot-command has a different function, it forces the current shell interpreter to run another shell script in it's own address space. Usually when a shell script is invoked (by a shell interpreter) this shell starts another shell interpreter to execute the script (which kind of interpreter is decided by the directive above). In the case a shell script name is preceded by a dot the new script will be handled by the same shell interpreter. Usually this 'sourcing' is done to load a set of shell parameters from a generic shell script somewhere.
    E.g. if you change your environment settings by editing your .profile and you want your changes to be effective right away you can either logoff and logon again or run:
    Code:
    . ${HOME}/.profile
    on the prompt.

    Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •