1752818 Members
4184 Online
108789 Solutions
New Discussion юеВ

LS on sh versus ksh

 
SOLVED
Go to solution
Pedro Cirne
Esteemed Contributor

LS on sh versus ksh

Hi,

I've a script in sh like:

for file in $(ls $DESTDIR_APT/{200mm,300mm}/*.{tdf,dat,ADF,EOK,LOT} 2>/dev/null)
do
compress -f $file
done

How can I do it in ksh?

Thks,

Pedro
6 REPLIES 6
Rick Garland
Honored Contributor

Re: LS on sh versus ksh

for FILE in `ls $DESTDIR_APT/{200mm,300mm}/*.{tdf,dat,ADF,EOK,LOT} 2>/dev/null)`
do
compress $FILE
done

No big changes - I did add some backticks.
Pedro Cirne
Esteemed Contributor

Re: LS on sh versus ksh

Hi Rick,

:(

It doesn't work that way..I want to ls all *.tdf *.dat *.ADF *.EOK *.LOT from both directories 200mm and 300mm

Thks
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: LS on sh versus ksh

First, don't use ksh on HP-UX; /usr/bin/sh which is not the Bourne shell but the POSIX is the preferred weapon and will do anything that ksh will do:

This should work:

for file in $(ls ${DESTDIR_APT}/+(200mm|300mm)/*\.+(tdf|dat|ADF|EOK|LOT) 2>/dev/null)
do
echo "File: ${file}"
#compress -f ${file}
done

The "+(pattern1|pattern2)" expression requires that at least one match be found.
If it ain't broke, I can fix that.
David Child_1
Honored Contributor

Re: LS on sh versus ksh

Try changing the line to:

for file in $(ls $DESTDIR_APT/+(200mm|300mm)/*.+(tdf|dat|ADF|EOK|LOT) 2>/dev/null)

David
Pedro Cirne
Esteemed Contributor

Re: LS on sh versus ksh

Hi,

Thank you all.

Pedro
Stuart Browne
Honored Contributor

Re: LS on sh versus ksh

I'm picking the reason Rick's didn't work is because he had a closing parenthasis ')' at the end, between his back-ticks (`).

But from what I've read (and used) of ksh on different platforms, I thought it understood both the back-tick method of subshells (var=`command`) as well as the bourn-$() style of inline subshell (var=$(command)).

But all that being said, the korn shell should also be able to survive without the 'ls' at all, and do direct shell expansion of the path, i.e.

for file in $DESTDIR_APT/{2,3}00mm/*.{tdf,dat,ADF,EOK,LOT}
do

but that assumes there will always be atleast one match ;)
One long-haired git at your service...