LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-05-2015, 07:26 AM   #1
pritidongare
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Rep: Reputation: Disabled
checking presence of a file identified/ addressed by a variable


hi,

I am newbie in Linux shell scripting.Can anybody help me to check the presence of file identified by variable in Shell scripting?

For example: I am reading the content of a file using while command as below:
"while read -r line
do
code block
done < file_name"

Now in this case every line in file gets stored in the variable 'line' one by one.Problem here is every line in the file is nothing but the file_path of another file say xyz.txt and I am checking presence of this xyz.txt file using below command:
if [-f $line]
as 'line' is the variable which stores file path of xyz.txt but it is not working. It is unable to check the presence of this xyz.txt file as i am addressing it with the variable 'line'.

Please help me.Thanks in advance.
 
Old 06-05-2015, 07:48 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
you should show us the real script, otherwise it will be very hard. But probably you only missed a space:
Code:
if [ -f $line ]
if^[^-f^$line^] << here all ^ should be replaced to spaces
 
1 members found this post helpful.
Old 06-05-2015, 08:21 AM   #3
pritidongare
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile

Thanks a lot pan64!!

I didn't five space before '-f' and it is working now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
checking /usr/include/ptlib.h presence... acbhaskar1 Linux - Server 1 06-25-2011 09:57 AM
Detect presence of a file s8utt Linux - Newbie 6 05-20-2009 06:41 AM
Checking variable is numeric ijf99 Programming 2 03-28-2009 09:13 AM
Checking whether a variable is alphabetic basildon Linux - Newbie 4 09-21-2008 05:03 PM
F-prot identified a suspicious file azebuski Linux - Security 1 03-05-2004 01:30 AM


All times are GMT -5. The time now is 10:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration