Reputation: 11
I made the following work on Linux (RHEL 6.x/7.x), however, there are Unix servers too running HP-UX (B.11.23/B.11.31).
My target isn't to make the same block to work for both envs, I can enforce them to run separately based on OS. But need to perform the following.
Please help me out finding an easy way to do the following on Unix.
#ABC="/u01/app/oracle /u02/app/oracle /u03/app/oracle"
array=($(echo $ABC | awk -F' ' '{for (i = 0; ++i <= NF;) print $i}'))
for i in "${array[@]}"; do echo $i; done
#
O/P ::
/u01/app/oracle
/u02/app/oracle
/u03/app/oracle
#
I want to get the same thing above done in Unix too. Problem is, there is no way I could find how to insert multiline awk output into an array at one shot like that is possible in RHEL.
Upvotes: 0
Views: 405
Reputation: 11
I have found a way to do this, good thing it works both with Linux and Unix.
countArr=0
for i in $ABC; do array[$countArr]=$i; countArr=$((countArr+1)); done
for i in "${array[@]}"; do echo $i; done
Upvotes: 1