Operating System - HP-UX
1838608 Members
3737 Online
110128 Solutions
New Discussion

removing command line parameters to shell a script

 
SOLVED
Go to solution
Srini Jay
Valued Contributor

removing command line parameters to shell a script

Hi All,
I have two shell scripts, say 'a' and 'b'.
Contents are as given below:

# file 'a'
echo "in a: $*"
. b
----------------------
# file 'b'
echo "in b: $*"
----------------------


When I invoke 'a' with some command line parameters, those are seen by 'b' also (sourcing effect); but I do not want 'b' to be aware of the command line parameters to 'a'.

Since 'b' sets environment variables for 'a', I have to source it as given above.

Also note that I cannot edit script 'b'.

Any ideas how to unset those command line parameters?
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: removing command line parameters to shell a script

Hi:

Use 'shift' to chop off the number of arguments before sourcing the second script:

# file 'a'
echo "in a: $*"
shift $#
. b

Regards!

...JRF...
Srini Jay
Valued Contributor

Re: removing command line parameters to shell a script

Thanks James!
That works!!!
A. Clay Stephenson
Acclaimed Contributor

Re: removing command line parameters to shell a script

Note that because "b" is invoked via "." (dot), that all of this is actually one process "a". There is no child process "b".

what you can do is:
set ""
. b

The set "" will clear all positional variables.

If you still need access to these variables in "a" after "b" has been invoked then you can save thenm in a temporary variable (which will be visible to "b" since it's the same process but presumably "b" will have no knowledge of your data hiding).

XX=${@}
set "" # positional variables are cleared
. b
set ${XX} # positional variables are now restored
If it ain't broke, I can fix that.
Rodney Hills
Honored Contributor

Re: removing command line parameters to shell a script

When you call b do-

. b ""

This will set the command parameters to empty.

Or you could use "shift $#" in a.

HTH

-- Rod Hills
There be dragons...