0

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.

3
  • 1
    Why don't you just say ABC=(/u01/app/oracle /u02/app/oracle /u03/app/oracle)? Commented Jun 17, 2016 at 12:08
  • And what shell do the HP-UX systems have? Commented Jun 17, 2016 at 12:10
  • I'm basically getting directories used by database for existing datafiles. Which comes with a space in between instead of a newline. ABC=sqlplus -s / as sysdba <<EOF set feed off set heading off set feedback off select distinct(substr(file_name,1,instr(file_name,'/', -1, 1))) from dba_data_files; exit EOF So it is pretty much formatted that way with above approach. I'm using korn shell (ksh) Commented Jun 17, 2016 at 14:31

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.