The script below is supposed to list file and folder names and list the type besides each - It has no practical value - I am just trying to learn KSH (so far sounds like a bad idea!)
Expected output should look like this:
folder 1 *** dir ***
file1 * file *
The code runs but produces strange wrong results.
I am using Microsoft SFU.
I would like to know what is wrog?
Thanks much.
#!/usr/bin/ksh
f=""
typ1=""
for f in `ls`
do
if [ -d "$f" ]
then
typ1=" *** dir ***"
elif [ -f "$f" ]
then
typ1=" * file *"
else
typ1=" Not sure?"
fi
print $f
print $typ1
done
Yes, I should include both variables in 1 print line.
I get the file names correct - The content of typ1 is I guess the one that is causing the problem...
The output seems to be a dump of all file names I have in the directory with every print of typ1, for example I get something like this:
"
l tee tee.exe.stackdump test2 tmp.3736 winrar.exe winwordcontrol_demo winwordcontrol_demo.zip word
net x x.txt x2 xml xml2 xs xx1 z z.$$$ z.sh z.txt z1.txt
Not sure?
2 ADO.NET The Complete Reference AGG.TXT Business Analysis.txt OCOUNTER_RTN.doc Counter_RTN.
Not sure?
"
I tried the script and it stated everything was a file, even though there are directories. Plus, I had already changed the print statement before seeing Perderabo's reply. Not exactly sure what GMMike is getting but that's why my question was asked!
I gave it a whirl after making the edit (well, I replaced the print's with a single echo) and it works as expected under "pdksh" (Linux) - Haven't tried it under SFU as I removed it from my Windows XP machine a while back to make way for Cygwin