![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Extracting the values separated by comma | padmisri | Shell Programming and Scripting | 6 | 07-31-2009 03:13 AM |
| Its PERL + Comma separated seventh field | ganapati | Shell Programming and Scripting | 17 | 06-24-2009 04:20 AM |
| validate a pattern of numbers that are comma separated | 12345 | UNIX for Dummies Questions & Answers | 5 | 05-08-2009 03:47 AM |
| comma separated string manipulation | saharookiedba | Shell Programming and Scripting | 2 | 02-13-2009 03:24 AM |
| Unix Comma Separated to Excel Column | ravzter | UNIX Desktop for Dummies Questions & Answers | 3 | 07-31-2008 03:46 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Parsing Comma separated Arguments
Hi unix guru's
I want to execute a shell script like ksh printdetails.ksh Andy,Bob,Daisy,Johnson like passing all the four names in the as the arguments and these arguments are varies between 1 to 10. How to pass these names to the shell script variable. and also i want to know the count of arguments passed to script. Thanks in advance. |
|
||||
|
Here's one way.
Code:
#!/bin/ksh
VARS=$1
set -A A_NAME $( echo "$VARS" | sed 's/,/ /g' )
NUM_VARS=${#A_NAME[@]}
while [ -n "${A_NAME[i]}" ]
do
echo "name = ${A_NAME[i]}"
(( i = i + 1 ))
done
echo "Total Names: ${NUM_VARS}"
Code:
./names.ksh mike,bill,jim,john name = mike name = bill name = jim name = john Total Names: 4 |
|
||||
|
And here is another way:
Code:
#!/bin/ksh oIFS="$IFS"; IFS=, ; set -- $1 ; IFS="$oIFS" for i in "$@"; do echo name = $i done echo Total Names: $# Code:
$>./test Cooper,"Billy Bob",Trevor,Smithers name = Cooper name = Billy Bob name = Trevor name = Smithers Total Names: 4 Last edited by Scrutinizer; 5 Days Ago at 03:01 AM.. |
|
||||
|
Hi Reddy, I do not understand what you mean exactly, could you be specific and/or give an example?
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|