Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

ksh arrays

Shell Programming and Scripting


Closed Linux or Unix Question    
 
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: 7 May 2015, 3:00 AM EDT
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: 5 July 2015, 2:26 PM EDT
Location: Amsterdam
Posts: 10,309
Thanks: 346
Thanked 2,725 Times in 2,437 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: 7 May 2015, 3:00 AM EDT
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: 5 July 2015, 2:26 PM EDT
Location: Amsterdam
Posts: 10,309
Thanks: 346
Thanked 2,725 Times in 2,437 Posts
Or:

Code:
array=(
  val1
  val2
  val3
)

Sponsored Links
Closed Linux or Unix Question

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 08:29 PM
Arrays in nawk and ksh Pablo_beezo UNIX for Dummies Questions & Answers 2 11-06-2008 05:59 AM
Export Arrays in ksh ricardo.ludwig Shell Programming and Scripting 3 10-06-2008 03:16 PM
Automatic Arrays in ksh Jonny2Vests Shell Programming and Scripting 1 02-27-2008 10:20 AM
KSH and arrays whited05 Shell Programming and Scripting 1 06-24-2005 12:07 PM



All times are GMT -4. The time now is 03:25 PM.