Re: Bourne shell script affecting current shell with arguments

From: Barry Margolin (barry.margolin@level3.com)
Date: 04/23/03


From: Barry Margolin <barry.margolin@level3.com>
Date: Wed, 23 Apr 2003 17:12:37 GMT

In article <3ea6b022.0@news>, Greg Jewell <gjewell@cnnxn.com> wrote:
>Hi All,
>
>We've got a script that is run by users running the Bourne shell to set
>environment variables needed by their current shell. The user passes some
>arguments to this script for the variables to be set. A sample script
>called "test.sh":
>
>VALUE=$1
>export VALUE
>
>When the user executes "test.sh 3", the parameter 3 is seen. However, when
>the user executes ". test.sh 3", the parameter 3 is not seen. Is there a
>way to get this to work under the Bourne shell? When the current shell is
>either Korn or Bash, it works as desired.

No, I don't think Bourne shell provides a way to pass parameters when
sourcing a script. I have two suggestions:

1) Have the user set a variable before running the script, and the script
   looks at the variable rather than a command-line parameter.

2) Have the script define a function that does the real work. The user
   sources the script to define the function, and then invokes the function
   with a parameter.

-- 
Barry Margolin, barry.margolin@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


Relevant Pages

  • Re: Bourne Shell Port Available
    ... >> I guess I'm happy for you, but I spend most of my time on Solaris ... >> boxes trying to avoid the Bourne shell. ... shell script that couldn't be run by ksh anyway. ... > obligation to the POSIX standard requires them to fix non-conforming ...
    (comp.unix.shell)
  • exit call in script causes unit test to not run (newby)
    ... I currently have a ruby script which I'm trying to create some ... If I comment out the exit then my tests actually run. ... something I commonly do in bourne shell scripts and it made sense to ... # Set PROTO constant based on command line arg ...
    (comp.lang.ruby)
  • Re: exec script in all subdirs; pathnames contain spaces
    ... unset CDPATH ... that was not a Bourne shell script. ... Inline is a "dummy" parameter. ...
    (comp.unix.shell)
  • Re: Help with very basic bourne shell
    ... simple script does not work in bourne shell. ... There is no let command in the Bourne shell; ... This script will be called by a cron job so I don't want any output. ...
    (comp.unix.shell)
  • Bourne shell script affecting current shell with arguments
    ... We've got a script that is run by users running the Bourne shell to set ... either Korn or Bash, it works as desired. ...
    (comp.unix.shell)