LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   checking presence of a file identified/ addressed by a variable (https://www.linuxquestions.org/questions/linux-newbie-8/checking-presence-of-a-file-identified-addressed-by-a-variable-4175544570/)

pritidongare 06-05-2015 06:26 AM

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.

pan64 06-05-2015 06:48 AM

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


pritidongare 06-05-2015 07:21 AM

Thanks a lot pan64!!

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


All times are GMT -5. The time now is 11:47 AM.