![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Longer commands and strange behaviour on ksh | anurags | UNIX for Dummies Questions & Answers | 2 | 03-27-2008 11:04 AM |
| Strange sed behaviour | vino | UNIX for Advanced & Expert Users | 8 | 02-12-2008 06:51 AM |
| A Strange Behaviour!!! | navojit dutta | Shell Programming and Scripting | 5 | 12-21-2007 04:35 AM |
| /etc/passwd strange behaviour! | penguin-friend | Linux | 0 | 06-06-2005 12:00 PM |
| very strange behaviour on unix server | bolo77 | UNIX for Dummies Questions & Answers | 7 | 03-02-2005 03:32 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
As you are probably aware, $# indicates the number of parameters passed into a korn shell script. But this appears to hang around for
sunsequent runs...???? A simple script:- #!/usr/bin/ksh echo "#parameters $#" echo "\$1 $1" echo "\$2 $2" I run the script with 0 parameters (all fine) # . par.ksh #parameters 0 $1 $2 Now run it passing 2 parameters (all fine) # . par.ksh aaa bbb #parameters 2 $1 aaa $2 bbb Now run it again with no parameters (and it still thinks there are 2)! # . par.ksh #parameters 2 $1 aaa $2 bbb If I add set -- (to unset positional parameters) it works! But I would have though that $# gets set every time its run, Any ideas anyone ????? |
|
||||
|
Hi!
I have tried what u did in AIX5.3, that uses ksh and it worked well. Code:
root@bbb:/> ./teste.sh ola #parameters 1 $1 ola $2 root@bbb:/> ./teste.sh ola bla #parameters 2 $1 ola $2 bla root@bbb:/> ./teste.sh ola bla edas #parameters 3 $1 ola $2 bla root@bbb:/> ./teste.sh #parameters 0 $1 $2 root@bbb:/> |
|
||||
|
Exactly this - once the script is run in the currect shell, once in a daughter shell - is reason for the different results.
The line ". ./x.ksh par1 par2" does the following: it starts in the current shell the script x.ksh and passes two parameters. These parameters are passed not to the script but to the process which runs the script. This process is the current process - our login shell. When the script is run again in the same process the two parameters passed to this process are still there. They can be displayed even in the commandline: Code:
# cat x.ksh #! /bin/ksh print - "$? parameters have been passed" exit 0 # print - $? 0 # there are no parameters # . ./x.ksh par1 par2 2 parameters have been passed # print - $? 2 # there still are the two parameters # . ./x.ksh 2 parameters have been passed See also this thread: How to clear $1 when dot-running a script. I hope this helps. bakunin |
|
||||
|
Hi i worked on linux with the same script, i didn't find wrong with the KSH behaviour
[saik@lnx02 mp]$ ./test.ksh #parameters 0 $1 $2 [saik@lnx02 mp]$ ./test.ksh 111 222 #parameters 2 $1 111 $2 222 [saik@lnx02 mp]$ ./test.ksh 111 222 333 #parameters 3 $1 111 $2 222 [saik@lnx02 mp]$ ./test.ksh 111 #parameters 1 $1 111 $2 [saik@lnx02 mp]$ ./test.ksh #parameters 0 $1 $2 [saik@lnx02 mp]$ Sai Kumar |
![]() |
| Bookmarks |
| Tags |
| linux, solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|