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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"List" question

Status
Not open for further replies.

jescat

Technical User
Jul 29, 2004
32
US
I am running this script in AIX (tried SH, KSH). I would like to pass in a comma deliminted list and have the script parse the list. I ran this same script in an HPUX environment and it works perfectly. I thought if I used the same shell it wouldnt matter what flavor of Unix it was on (obviously I was incorrect).

send_page() {
for DBA in ${1}; do
echo in
echo $DBA
case $DBA in
jesse) echo "jesse";;
mika) echo "mika";;
esac
done
}
send_page "$1"

At the command I type "t.sh jesse"

output is:

in
jesse
jesse

This is correct

When I run "t.sh "{jesse,mika}"

output is:

in
{jesse,mika}

This is not correct I expected the following results

in
jesse
jesse
mika
mika

I have tried different variation with the syntax and nothing seems to work. As I said this scripts works perfectly on HP so how do I port this functionality over to AIX.

Thanks
JS
 
I get this output with my ksh:
in
jesse
jesse
in
mika
mika
 
Ummm..interesting.

Are using AIX/HP/Sun. I originally built this script in HP and like I said it worked fine. I am currently working in an AIX environment and I am getting the bizarre results I noted.

JS
 
Are you certain it is running under Ksh? If you don't have a #!/bin/ksh shebang line at the beginning of the script it may be defaulting to run it in sh, even if the calling shell is Ksh.

Annihilannic.
 
Here is the script:

#!/bin/ksh
send_page() {
for DBA in ${1}; do
echo in
echo $DBA
case $DBA in
jesse) echo "jesse";;
mika) echo "mika";;
esac
done
}
send_page "$1"


$t.sh jesse
in
jesse
jesse


$t.sh {jesse,mika}
in
{jesse,mika}


 
I got it, there is another Korn shell (ksh93) that they have. I used this one and it works appropriately.

Thanks
JS
 
Try this...
Code:
#!/bin/ksh
send_page() {
IFS=,
for DBA in ${1}; do
   echo in
   echo $DBA
   case $DBA in
      jesse) echo "jesse";;
      mika) echo "mika";;
   esac
done
}
send_page "$1"
And don't run it with the braces around the names. Try this...
Code:
$ t.sh jesse,mika
in
jesse
jesse
in
mika
mika
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top