Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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/*

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

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

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 starwhile 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 < infileHow can I get each field in the input line from a text file?
Thank you.
Apple

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 < infileIf 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

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.

![]() |
![]() |
![]() |

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