[Solved] How to refer more than 9 command line inputs for a scripts in korn shell?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] How to refer more than 9 command line inputs for a scripts in korn shell?
# 8  
Old 12-04-2013
What does sh resolve to? I doubt it's ksh or bash by default on SunOS.

Try
Code:
ksh displayname.sh a b c d e f g h I j k l m n o p q r s t u v

# 9  
Old 12-04-2013
Quote:
Originally Posted by CarloM
What does sh resolve to?
probably not a POSIX shell as the standard describes this situation and tells to use braces.
# 10  
Old 12-04-2013
Quote:
Originally Posted by pat_pramod
Thank you for your input everyone. I am trying this and the output is also pasted here.
Code:
/export/home/pj317q> cat displayname.sh
echo $1
echo $2
echo $9
echo ${15}
echo ${10}
/export/home/pj317q> sh displayname.sh a b c d e f g h I j k l m n o p q r s t u v
a
b
I
displayname.sh: bad substitution
/export/home/pj317q>

Not sure whats going wrong.
Note that you're using sh; not ksh to run the script (as marked in red above). But the old Bourne shell on Solaris 8 should also be happy with ${15} and ${10}. What is the output from the command:
Code:
type sh

# 11  
Old 12-04-2013
For information, from my "solution" with shift command, it was on solaris 10 (/usr/bin/sh).

It is possible that a shopt or set -o option is missing ?

Regards.
# 12  
Old 12-04-2013
Quote:
Originally Posted by disedorgue
For information, from my "solution" with shift command, it was on solaris 10 (/usr/bin/sh).

It is possible that a shopt or set -o option is missing ?

Regards.
Note that neither Solaris 10 /usr/bin/sh nor Solaris 8 /bin/sh or /usr/bin/sh (I thought it was /bin/sh on a Solaris 8 system, but it has been many years since I had access to a Solaris 8 system) is a Korn shell; they are Bourne shells. But both Bourne and Korn shells should be happy with ${12} when there are that many command line arguments no matter what shell options are enabled.

Of course you can use shift 10 to access positional parameters 11 through 19 as $1 through $9, respectively, in a Bourne or Korn shell. But after the shift, the original positional parameters $1 through ${10} (if it worked) will no longer be available unless they were saved into other variables before the shift 10. If ${10} isn't working and you need to access the 10th positional parameter, presumably you'd want to use shift 9 rather than shift 10 so you could process groups of 9 positional parameters at a time. Even after a shift, $0 should remain unchanged (but if ${11} doesn't work, I won't make any claims about how $0 will behave after any invocation of shift).

Have you or pat_pramod tried running any of these scripts with /usr/xpg4/bin/sh or with ksh instead of using /usr/bin/sh or /bin/sh?
# 13  
Old 12-05-2013
In Solaris, /usr/bin/sh is not a POSIX shell, it is some sort of Sun homebrew shell based on the bourne shell. If you want a POSIX shell, use /usr/xpg4/bin/sh or the /usr/bin/ksh as Don Cragun already suggested.

Code:
$ /usr/bin/sh -c 'set a b c d e f g h i j k l m n o; echo ${12}'
/usr/bin/sh: bad substitution
$ /usr/xpg4/bin/sh -c 'set a b c d e f g h i j k l m n o; echo ${12}'
l
$ /usr/bin/ksh -c 'set a b c d e f g h i j k l m n o; echo ${12}'
l

The result is the same on Solaris 8 and 10.

BTW: In Solaris, /bin is a symbolic link to /usr/bin/, so /bin/sh and /usr/bin/sh are identical.
This User Gave Thanks to hergp For This Post:
# 14  
Old 12-05-2013
It's ok for /usr/xpg4/bin/sh, ${20} for exemple work fine.
I check my /usr/bin/sh and /bin/sh, and they are a link to /sbin/sh

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script? (4 Replies)
Discussion started by: Sree10
4 Replies

2. Shell Programming and Scripting

[Solved] Finding a word in all shell scripts

Hi i have to find the shell script that contain the word PROC__TO_UPDATE SEARCH SHOULD BE INSENSITIVE AND SCRIPT CAN BE DEPLOYED IN ANY PATH. I am on Solaris. (27 Replies)
Discussion started by: rafa_fed2
27 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Korn Shell execution

There are two Korn Shell scripts : script_1.ksh ( located in /home/dir1 ) script_2.ksh ( located in /home/dir2 ) Content of script_2.ksh is #!/usr/bin/ksh echo "Hello world.." The script_2.ksh is called from within script_1.ksh using the following command : ./home/dir2/script_2.ksh but... (7 Replies)
Discussion started by: kumarjt
7 Replies

4. Shell Programming and Scripting

[Solved] Issue with using for loop as for in {2..6} in korn shell

Hi i have to cut columns 2 to 6 from a file and assign it to arrays , The following code works for ctcol in 2 3 4 5 6; do set -A a$ctcol $(cut -d, -f $ctcol test_file) done how ever this does not work for ctcol in {2..6}; do set -A a$ctcol $(cut -d, -f $ctcol test_file)... (4 Replies)
Discussion started by: 100bees
4 Replies

5. UNIX for Dummies Questions & Answers

[Solved] How to refer to input file in code?

This may be a dumb question, but googling is not giving me an answer. I'm trying to figure out how to refer to an input file in my code. Lets say i run a script in bash: "sh shellscript.sh inputfile" (Inputfile will be variable...whatever file i run the script on) I wanted to make... (5 Replies)
Discussion started by: legato22
5 Replies

6. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

7. Programming

How to refer to variable (korn shell)?

Hi I have the following block of code in korn shell and don't now how to refer to variable `print variable1.$dvd` ? --- integer dvd=4 integer number=0 while (( dvd!=0 )) do print "Iteracja numer : $dvd" print "$_" #it refers to $dvd var but want to refer... (3 Replies)
Discussion started by: presul
3 Replies

8. Shell Programming and Scripting

Vaildation of command line inputs

Hi, I want to do the following validations in my script when my script gets 2 parameters as command line inputs. My script expects 2 inputs : a -f option and a filename If a filename is given as input without the -f option then I have to exit. If only -f option is given and no filename is... (6 Replies)
Discussion started by: sendhilmani123
6 Replies

9. Shell Programming and Scripting

Command line inputs validation

Hi, I have a script called read.sh that takes a file as input. Now I want to make that script take the file as input with a -f option preceding the filename. How can I do this validation. How can I find whether the given option is -f or not inside the script. Thanks in advance (2 Replies)
Discussion started by: sendhilmani123
2 Replies

10. UNIX for Advanced & Expert Users

Error Handling in Korn Shell scripts

Hi, I am using few ISQL statements to update and delete from a few tables in sybase, now i want to roll back the transaction when any of the statements fail.How i can i capture these errors in the shell scripts.Please advise. Thanks, Gopi (4 Replies)
Discussion started by: bhgopi
4 Replies
Login or Register to Ask a Question