# to search a file if it exists and whether its readable or not
# if yes print its first 5 lines
echo enter the filename to be searched
read fname
if [ ! -e $fname ] #-d $fname
then
echo file doesn exists
elif [ -d $fname ]
then
echo its a directory
elif [ -r $fname ]
then
cat $fname
else
echo its not readable
fi
# end of program
###########################
this program is running fine but is getting a warning message i guess
it says
/filesearch2.ksh[5]: test: argument expected
and then showing the result.
please suggest
# to search a file if it exists and whether its readable or not
# if yes print its first 5 lines
echo enter the filename to be searched
read fname
if [ ! -e "$fname" ] #-d $fname
then
echo file doesn exists
elif [ -d "$fname" ]
then
echo its a directory
elif [ -r "$fname" ]
then
cat "$fname"
else
echo its not readable
fi
# end of program
but still showing the same error !!
and no.. my $fname is not blank as i am getting the contents of this filename as it is supposed to be.
but still getting the error/warning msg :
filesearch2.ksh[5]: test: argument expected
##########
and yes, i am not getting .. what u r referring when u say "code tag" . plz explain so that i'll post in my next threads to get served better !!
$ ./MyTest
enter the filename to be searched
blah
file doesn exists
It's also not bad practice to quote strings, like echo's, etc.
As for CODE-TAGS:
z.I.
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
@scottn
in general Korn Shell is not a POSIX shell but I believe that ksh93 is one.
I find the various inconsistent implementations of POSIX "standards" over the years tiresome and prefer ksh88 syntax for cross-platform portability. This includes using "cat" where necessary.
What O/S do you have where "test -e" works in ksh?