Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEWB: how to reset $1 in multiple calls to scripts

Status
Not open for further replies.

misterstick

Programmer
Apr 7, 2000
633
GB
AIX 4.3.3
i have a script which i wish to run with and without parameters.
when run without, it should use a default value.
when i run the script first with a parameter, and then without, the second time the script behaves as if there were still one parameter.

example script:
Code:
!#/bin/ksh
echo $# $1

example session:
Code:
$ . script.sh parameter
1 parameter
$ . script.sh
1 parameter
$ echo $# $1
1 parameter

is there any way to stop this behaviour?
many thanks,



mr s. <;)

 
You're setting $# and $1 in your current shell by executing script.sh using the dot (.) command.

Make it executable so it runs in a subshell...

FJC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top