Comparing 2 Arrays in shell script -
i have read contents of folder , store them in array. , need pass array script. how can store , pass array , read array??
#!/usr/bin/ksh cd /path/applications-war arraywar=( $(ls /path/applications-war))
i need contents under folder array (@arraywar). login box , call script. need pass array script.
/usr/bin/ssh -t -t username@machinename /path/myscript.sh @arraywar
inside myscript.sh, want compare passed array @arraywar servicesarray.
#!/bin/ksh @arraywar = $1 servicesarray=('abc.war' 'xyz.war') warfile in @arraywar if echo "${servicesarray[@]}" | fgrep "$warfile"; echo "$warfile matches" else echo "$warfile not matched" fi done
here's script, takes variable number of files arguments:
#!/bin/ksh servicesarray=('abc.war' 'xyz.war') warfile in "${@##*/}" if echo "${servicesarray[@]}" | fgrep "$warfile"; echo "$warfile matches" else echo "$warfile not matched" fi done
you call script (note using ls
not recommended):
arraywar=( /path/applications-war/* ) /usr/bin/ssh -t -t username@machinename /path/myscript.sh "@{arraywar[@]}"
you can dispense arraywar
, , pass list of files directly
/usr/bin/ssh -t -t username@machinename /path/myscript.sh /path/applications-war/*
Comments
Post a Comment