Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

ksh arrays

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-30-2013
Subbeh Subbeh is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 March 2016, 7:23 AM EST
Posts: 332
Thanks: 37
Thanked 87 Times in 86 Posts
ksh arrays

Hi,

I have a ksh script in which I need to fill an array with a list of filenames.
It currently works like this:

Code:
set -A array \
  val1 \
  val2 \
  val3

However, I was wondering why it's not possible to do something like this to make it easier to parse values to the array:

Code:
set -A array <<EOF
  val1
  val2
  val3
EOF

Sponsored Links
    #2  
Old Unix and Linux 01-30-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 4 December 2016, 10:28 PM EST
Location: Amsterdam
Posts: 11,101
Thanks: 440
Thanked 3,108 Times in 2,749 Posts
Because it would be syntactically incorrect. You could however do this:

Code:
set -A array $(
cat << EOF
  val1
  val2
  val3
EOF
)

The Following User Says Thank You to Scrutinizer For This Useful Post:
Subbeh (01-30-2013)
Sponsored Links
    #3  
Old Unix and Linux 01-30-2013
Subbeh Subbeh is offline
Registered User
 
Join Date: May 2011
Last Activity: 3 March 2016, 7:23 AM EST
Posts: 332
Thanks: 37
Thanked 87 Times in 86 Posts
Thanks, that makes sense
    #4  
Old Unix and Linux 01-30-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 4 December 2016, 10:28 PM EST
Location: Amsterdam
Posts: 11,101
Thanks: 440
Thanked 3,108 Times in 2,749 Posts
Or:

Code:
array=(
  val1
  val2
  val3
)

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multidimentional arrays in KSH hraj1984 Shell Programming and Scripting 8 12-15-2011 09:29 PM
Arrays in nawk and ksh Pablo_beezo UNIX for Dummies Questions & Answers 2 11-06-2008 06:59 AM
Export Arrays in ksh ricardo.ludwig Shell Programming and Scripting 3 10-06-2008 04:16 PM
Automatic Arrays in ksh Jonny2Vests Shell Programming and Scripting 1 02-27-2008 11:20 AM
KSH and arrays whited05 Shell Programming and Scripting 1 06-24-2005 01:07 PM



All times are GMT -4. The time now is 10:36 AM.