sh_kk
1
Hi All,
I am a newbie to Shell programming and stuck with the folllowing issue:
Here is the code:
#! /bin/sh
if [ls "$1"];
then
echo "Checking if the file is found or not"
fi
On running, I get the following error:
spk265@linax1[~]$ ./shell ./sample/samplenew
./shell: line 3: [ls: command not found
I have written this code to check if a file exists at the locn specified.
Waiting for response
Regards!
daptal
2
replace it with
if [ `ls $1` ];
then
echo "Checking if the file is found or not"
fi
sh_kk
3
Hi,
Thanks for your help.
I have another query:
The code should be checking if a file exists or not.
When I run the command for a existing file, the message is printed. But the same happens for a non-existent file.
What can be the issue?
ls command returns a error when run in isolation with the filename. How should I capture the error message?
rdcwayx
4
check the file is exist or not, should use -f
if [ -f "$YOUR_FILE" ] ; then