Thursday, December 18, 2008
Join two arrays in bash script
I already discussed about bash array in one of my older post . Here is a simple bash script to show how we can join two arrays field by field.
$ cat combarr.sh
#!/bin/sh
COUNTRY=( "Japan" "China" "India")
CAPITAL=( "Tokyo" "Beijing" "New Delhi")
n=${#COUNTRY[@]} #num elements in array COUNTRY
for (( i=0; i<n; i++ ))
do
COMB[$i]=${COUNTRY[$i]}"["${CAPITAL[$i]}"]"
echo ${COMB[$i]}
done
Executing:
$ ./combarr.sh
Japan[Tokyo]
China[Beijing]
India[New Delhi]
Related post:
- Introduction to bash array
- Combine array in bash
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
2 comments:
this is awesome, thanks!
This is brilliant. Thank you.
Post a Comment