1
LS=`ls "$SRC_PATH"/* | grep -i -v *.ignore`

I cannot use for loop as I need to check conditions with while as there are multiple conditions.

Trying to access the content using

${LS[$CNT]}
CNT=`expr $CNT + 1`

I am unable to access the contents.

2

We'll start with Do not parse the output of ls because it's always good to remind people of this.

Next note that the grep probably isn't doing what you want; you likely want \.ignore$ to make it skip files ending with ".ignore"

Since we're using ksh you don't need to call expr; you can just do let CNT=CNT+1

Now..

To set an array in ksh you need to use set -A syntax.

eg

set -A LS $(ls "$SRC_PATH"/* | grep -i -v '\.ignore$')

Now ${LS[0]} will be the first file, etc etc.

eg if we have

$ ls X               
a  b  c

Then

$ set -A LS $(ls X)
$ echo ${LS[0]}
a
$ echo ${LS[1]}
b
$ echo ${LS[2]}
c
  • Thank you very much, this worked. – Bootham Deyyam Jan 13 at 19:33

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.