f



Simple Unix Shell Script

Hi,

I am trying to execute a simple shell script to set the environment
variables.
It runs fine without any errors but i doesn't sets the environment
variables. I don't know what is wrong with the shell script.

I am using korn shell.
One more thing, is there anyway that same shell scripts can be run in
Bourne,C , Korn shell without any modification. I mean to say that we don't
have have to change the way they set different environment variables.

Any help will be greatly appreciated.

Thanks
Arun
-----------------------------------------------------
#! /bin/ksh -f
set -vx
cur_shell=`basename $SHELL`
LOCAL_DIR=/home/ag

echo "Your shell is : $cur_shell"

if [ $cur_shell = "ksh" ]
then
    #either csh or tcsh
    type=type1
    echo "$type"
fi

#Setting Env variables
if [ $type = "type1" ]
then
 LEDA=${LOCAL_DIR}
 export LEDA
fi


0
Arun
6/26/2003 10:52:21 PM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

1 Replies
892 Views

Similar Articles

[PageSpeed] 15

[This properly belongs in comp.unix.shell; Follow-up set]

On Thu, 26 Jun 2003 at 22:52 GMT, Arun Goel wrote:
> Hi,
> 
> I am trying to execute a simple shell script to set the environment
> variables.
> It runs fine without any errors but i doesn't sets the environment
> variables. I don't know what is wrong with the shell script.

    A script (or any other program) cannot change the environment of
    its parent process. However, there is a method, called sourcing,
    which allows a script to be run as part of the calling process.
    The syntax is: ". /path/to/script", e.g.;

.. $HOME/bin/my_script

    If it's in your PATH, you can just do:

.. my_script

> I am using korn shell.
> One more thing, is there anyway that same shell scripts can be run in
> Bourne,C , Korn shell without any modification. I mean to say that we don't
> have have to change the way they set different environment variables.

    There are two basic types of shell, Bourne (sh, ksh, bash, et al)
    and C (csh, tcsh); with very few exceptions, scripts written for
    one type will not run in the other. Scripting in csh is not
    recommended. See these documents for reasons:

        <http://www.grymoire.com/Unix/CshTop10.txt>
        <http://www.grymoire.com/Unix/Csh.html#uh-0>
        <http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>

    Scripts written for a Bourne shell will (with a few gotchas) run
    in any other Bourne-type shell.

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
0
Chris
6/27/2003 3:21:03 AM
Reply: