1834431 Members
2232 Online
110067 Solutions
New Discussion

Shell script array

 
SOLVED
Go to solution
Jason Tan
Advisor

Shell script array

how to use array in shell script? can show me examples on how to assign/extract value on array? If i'm going to assign nearly thousand of value into array, can it support?

I have this situation, i got list A and list B. I need to compare value on list A and B and output ONLY value that is same on both list, got better idea others than diff command?
smtan
5 REPLIES 5
Jdamian
Respected Contributor

Re: Shell script array

Did you try 'comm' command ?
john korterman
Honored Contributor

Re: Shell script array

Hi,
an aexample of a ksh array (up to 1024). First, assign some values:

# list_A[1]="position no. 1"
# list_A[2]="position no. 2"
# list_A[0]="position no. zero"
# list_A[1023]="position no. 1023"

Then, show the content:

# echo ${list_A[0]}
position no. zero

# NUMBER=1022
# echo ${list_A[$NUMBER+1]}
position no. 1023

Regards,
John K.
it would be nice if you always got a second chance
Carlos Fernandez Riera
Honored Contributor

Re: Shell script array


some more commands:

sdiff
join
unsupported
Julio Yamawaki
Esteemed Contributor

Re: Shell script array

Also, you can define a string using set -A a b c d e f

and address this VAR_NAME using
$VAR_NAME[0]....
Stanimir
Trusted Contributor
Solution

Re: Shell script array

Try to use /after small modifications/ this:

for unm in `awk -F: '{print $1}' /etc/passwd`; do
par1=`grep "$unm" /etc/group`
if [ "$par1" = "" ]; then
echo "no matches for unm"
else
echo "$unm already has in /etc/group"
fi
done

Regards,Stan