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

CNT=`expr $CNT + 1`

I am unable to access the contents.


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


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


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


$ set -A LS $(ls X)
$ echo ${LS[0]}
$ echo ${LS[1]}
$ echo ${LS[2]}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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