The following Ksh script gives me “No such file or directory” error message on Red Hat Linux system. Does anyone has a solution?
#!/usr/bin/ksh
for f in `cat files.dat`
do
wc $f
done
For example, files.dat has 3 lines of data and each line is a file in the current directory where the script is running from.
a.c
a.h
b.c
Note, the same for loop generated the same error message if running from command line too.
It works on Solaris/Mac box but not on Red Hat system.
Thanks.
Instead of
for ... cat, you should useAnd you should use
$()instead of backticks when you do need to do command substitution.But your problem is probably that the files
a.c, etc., are not there, have different names, invisible characters in their names, or the line endings infiles.datare CR/LF (DOS/Windows-style) instead of\n(LF only – Unix-style) or there are odd characters in the file otherwise.