Computing.Net > Forums > Unix > Unix - Ksh

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix - Ksh

Reply to Message Icon

Name: Apple
Date: March 19, 2005 at 05:02:22 Pacific
OS: ?
CPU/Ram: ?
Comment:

Dear All,
After I exec the script, how come does not show - Processing $fname.... I try to debug, I found the script stop at ->
if test -f $fname ;

Would anyone help me what's wrong I have?
Thank you.

while true
do
for fname in $(ls /home/file/)
do
if test -f $fname ; then
echo "Processing $fname..."
fi
done
sleep 60
done




Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: March 19, 2005 at 15:26:57 Pacific
Reply:

Can't see anything wrong with it. Works for me.

Not that it's any help, but isn't this:

for fname in $(ls /home/file/)

the same as this:

for fname in /home/file/*


0

Response Number 2
Name: gurubit
Date: March 21, 2005 at 06:27:15 Pacific
Reply:

It works fine for me as well.
Try removing the semi colon. That might be stopping the whole thing there.

Use like this.

#!/bin/ksh
while true
do
for fname in $(ls /home/pandera/)
do
if test -f $fname
then
echo "Processing $fname..."
fi
done
sleep 6
done


0

Response Number 3
Name: Jim Boothe
Date: March 21, 2005 at 06:47:33 Pacific
Reply:

The ls is returning simple file names, not fullpath names, so you need to change the if-statement to:

if test -f /home/file/$fname ; then


0

Response Number 4
Name: Apple
Date: March 21, 2005 at 07:59:32 Pacific
Reply:

Dear All,

Thank you for yours help.

When I run the script, I find that the error shows : "test" command not found.
If my OS-Unix may not have the command - "test", what's other command I can use?

I have another question?

inputfile name : infile
contain: sky moon sun star

while read
do
$1=cat infile | cut -c1-3
$2=cat infile | cut -c5-4
$3=cat infile | cut -c10-3
$4=cat infile | cut -14-4
done < infile

How can I get each field in the input line from a text file?

Thank you.
Apple



0

Response Number 5
Name: nails
Date: March 21, 2005 at 08:33:00 Pacific
Reply:

Hi:

I'm not certain what you're doing with that while loop, but if you have a file with a known number of columns, you can do this:

#!/bin/ksh

while read col1 col2 col3 col4
do
echo $col1
.
.
done < infile

If you don't, you can always use cut, but I prefer to use the set command which sets the command line arguments $1, $2 ..:

#!/bin/ksh

while read line
do
set - $(echo $line)
echo $1 # sky
echo $2 # moon
.
.
done < infile



0

Related Posts

See More



Response Number 6
Name: WilliamRobertson
Date: March 21, 2005 at 16:21:29 Pacific
Reply:

In ksh and others,

[[ -f filename ]]

is equivalent to

test -f filename

btw, why "cat infile | cut -c1-3"? Seems odd when cut can take a filename argument.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix - Ksh

Unix shell script for opening a file and www.computing.net/answers/unix/unix-shell-script-for-opening-a-file-and/3452.html

(Unix - Ksh) - How do i prompt user www.computing.net/answers/unix/unix-ksh-how-do-i-prompt-user/7126.html

Unix-ksh script www.computing.net/answers/unix/unixksh-script/6758.html