Hi all,
I have a question does anyone know if it is possible to push or pop an array in the ksh environment? Could anyone give me a hint, because I am trying to merge 2 server files together and there are some names in the server is not proper anymore.
typeset -i count=0
set -A array1 ab bx cd ef
# "ab bx cd ef" are the list of servers
while [ count -le ${#array1[@]} ] && [ count -ge 0 ]
do
# testfunction will return
# 1 = pass
# 0 = fail
test=$(testfunction array1[count])
if [[ $test -eq 1 ]]; then
echo "${array1[count]}_server"
fi
--------------------------------------------------------------------------
Above are the section of codes that I am having problem, when I ran this scripts, it will return the server name that I wanted along with the server name that I don't want
Output:
ab_server
bx
cd_server
ef_server
So are there some way to pop "bx" from the server list? I mean after it goes through the (testfunction). Thank you.
Well, figured it out. There are no push/pop for array in UNIX KSH. What I had done is that I cat the server names to a file and use sed to do my job, and then append those server name back to the array again. Hope this trick would help other when they want to do push/pop with an array.