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

put comma separated string in array

Status
Not open for further replies.

sourabhjha

Programmer
Jan 13, 2002
121
IN
Hi,
What is the function i shall use to put a command separated string into an array.My req is to put the comma separated strings into an an array and loop through them

Thanks,
-Sourabh
 
#!/bin/ksh

str="a,comma,separated,string"

OFS=$IFS
IFS=","
set -A arr $(echo "$str")
IFS=$OFS

# echo the whole array
echo ${arr[*]}
 
Thanks olded
Will need just a further help.
Here is what my script(getdata.sh) is.
It take comma separated filesystem names as input parameter.It should return the same comma separated space usage(%) data for those filesystems
-------start------------
#!/bin/ksh
filesystems=$1
OFS=$IFS
IFS=","
set -A arr $(echo "$filesystems")
IFS=$OFS
echo ${arr[*]}

#browse through the filesystems and get the %space used
i=0
while [[ $i -lt ${#arr[*]} ]]
do
echo ${arr[$i]}
filesystem=${arr[$i]}
spaceusage=`df -k|grep $filesystem|cut -d" " -f5,5,8`
${arr[$i]}=$spaceusage
echo ${arr[$i]}
let i=i+1
done
---------------end---------------
i run this file named getdata.sh with
$./getdata.sh /eai01,/eai02
I get some syntax error when i run this
./getdata.sh[44]: /eai01=: not found


I am also not getting "df -k|grep $filesystem|cut -d" " -f5,5,8" command right here.It does not return the % usage in all the cases.

See what all can u help here.

Thanks,
-Sourabh
 
Hi:

I "think" you're trying to grab the 5th field from the output of df -k command. I too am having trouble with the cut command. Why don't you use awk:

df -k|grep $filesystem|awk ' { print $5 } '
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top