Query on File checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Query on File checking
# 1  
Old 11-18-2009
Query on File checking

Hi All,

I am a newbie to Shell programming and stuck with the folllowing issue:

Here is the code:

#! /bin/sh

Code:
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!
# 2  
Old 11-18-2009
replace it with

Code:
if [ `ls $1` ];
then
           echo "Checking if the file is found or not"
fi

# 3  
Old 11-18-2009
Quote:
Originally Posted by daptal
replace it with

Code:
if [ `ls $1` ];
then
           echo "Checking if the file is found or not"
fi


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?
# 4  
Old 11-18-2009
check the file is exist or not, should use -f

Code:
if [ -f "$YOUR_FILE" ] ; then

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

2. Shell Programming and Scripting

Awk: File Checking Issues with 9 multiple file

Hi, I have 9 files which are generated dynamically & if there is a some condition which doesn't meet the criteria then file is not created or is of zero size. so further i am unable to consolidate the files based on following code 1 awk -F, -v ptime="201407" 'FNR==1... (3 Replies)
Discussion started by: siramitsharma
3 Replies

3. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

4. Shell Programming and Scripting

File checking

Hello Experts, File contains 5 columns with | delimeter. 1,3,5 columns are required columns means it should contains values. reset of the columns it will contain value or not. test1.txt: a@a.com|a|b|c|d |a|b|c|d output: test2.txt a@a.com|a|b|c|d I need the unix script, read the... (5 Replies)
Discussion started by: muralikri
5 Replies

5. Shell Programming and Scripting

File checking

Hi, I have to check file is available in particular directory. if ( -d $dir ){ print "It will say that is dir "; else print "It will say that is not dir"; } Not like this. I want to check that dir having files or not ? Please advice Thanks, Mani (1 Reply)
Discussion started by: Mani_apr08
1 Replies

6. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

7. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

8. Shell Programming and Scripting

Checking for a control file before processing a data file

Hi All, I am very new to Shell scripting... I got a requirement. I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data... (4 Replies)
Discussion started by: purna.cherukuri
4 Replies

9. Shell Programming and Scripting

Multiple file existence and checking file size

I want to check the files in particular directory are more that 0 Bytes i.e, Non zero byte file. The script should print a msg if all the files in that directory are empty( 0 Byte). (2 Replies)
Discussion started by: lathish
2 Replies

10. Shell Programming and Scripting

Error checking a file from previous file size

Hi, I'm currently trying to write a script that checks a log file for certain errors. Once checked it then records the filesize in another file. All this is fine, my problem is that the next time I do my error check I only want to check from previously recorded filesize to the end of file. I'm... (2 Replies)
Discussion started by: stuck1
2 Replies
Login or Register to Ask a Question