Files test How to recover a specific variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Files test How to recover a specific variable
# 1  
Old 09-18-2016
Files test How to recover a specific variable

Hi everyone !Smilie

I'm Arnaud and I'm new on this forum, I begin in the Shell. Let me explain, I want to test the presence of file, so far so good. Below, my code :
Code:
if [ -e "$fichier1" ] && [ -e "$fichier2" ] && [ -e "$fichier3" ] ; 
then 
        Pgsql ; 
else 
        echo \nLe fichier $fichier n\'existe pas ;

I would like to recover in a variable $fichier, only the file doesn't exist. I want to it like that to avoid many "if" Can you help me please. Sorry for my english, I begin also Smilie Smilie
# 2  
Old 09-18-2016
Try:

Code:
for fichier in fichier1 fichier2 fichier3; do
  if [[ -e ${fichier} ]]; then
        Pgsql
  else
        echo \nLe fichier ${fichier} n\'existe pas ;
  fi
done

This User Gave Thanks to pilnet101 For This Post:
# 3  
Old 09-18-2016
Thank you for your quick reply, that work fine Smilie
# 4  
Old 09-19-2016
Quote:
Originally Posted by Arnaudh78
I would like to recover in a variable $fichier, only the file doesn't exist.
What is the desired result, if more than one file does not exist? Should fichier then be an array holding the names of these files?
# 5  
Old 09-19-2016
Hi rovf, Below this is my desired result for example :

Code:
if [ -e "$fichier1" ] && [ -e "$fichier2" ] && [ -e "$fichier3" ] ; 
then
        Pgsql ; 
else
        echo \nLe fichier $fichier1 has not been found ; or echo \nLe fichier $fichier2  has not been found or echo \nLe fichier $fichier3  has not been found


I would like that the output me says only the file that not exist.. sorry if I am not very clear

Last edited by Arnaudh78; 09-19-2016 at 07:33 AM..
# 6  
Old 09-19-2016
Quote:
Originally Posted by Arnaudh78
Hi rovf, Below this is my desired result for example :

Code:
        echo \nLe fichier $fichier1 has not been found ; or echo \nLe fichier $fichier2  has not been found or echo \nLe fichier $fichier3  has not been found

I would like that the output me says only the file that not exist.. sorry if I am not very clear
Well, from a linguistic point of view, when listening exactly the non-existing files, the connection word should not be or, but and, but anyway: In this case you have two choices: Output the missing bits piece by piece, or collect everything into one array and output the result afterwards. I would go for the latter. Here is a sketch of the program:

Code:
declare -a missing 
for name in $fichier1 $fichier2 $fichier3 ....
do
     [[ -e $name ]] || missing[${#missing[*]}]=$name
done

if (( ${#missing[*]} == 0 ))
then
    Pgsql
else
    echo "Missing: " ${missing[*]}
fi

This User Gave Thanks to rovf For This Post:
# 7  
Old 09-19-2016
Thank you for the very good answer, you help me a lot! For me the post is solved. SmilieSmilieSmilieSmilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to Recover Deleted Files

Hi, By mistake, executed the following command : rm -rf * and ALL files got deleted. But I need to get back these files as they are very very important. Please help me how to recover this file. Its Urgent for me please. Thanks in advance. (6 Replies)
Discussion started by: unx100
6 Replies

2. UNIX for Dummies Questions & Answers

Recover directory/files in unix

Hi Guys I accidently deleted a directory( and the files in it) in unix using 'rm -rf' :) Is there any procedure/script/command to recover the same? Your help is highly apperciated -thanks Subramanya (1 Reply)
Discussion started by: sgbhat
1 Replies

3. UNIX for Dummies Questions & Answers

how to recover deleted files in unix

Hi Experts, by mistake i deleted some files that are very important to the project. is there any way that i can recover those files,there is no backup for that but the details of the file we know. This will be a great help. Thanks (5 Replies)
Discussion started by: namishtiwari
5 Replies

4. UNIX for Dummies Questions & Answers

Recover data from 2 files then combine

Using dd or similar tools to recover data from 2 damaged cdroms, I need a way to then combine the 2 files, 1 from each cd, and make a good file: this all result from finding that certain cd's tops scratch easily even when using the "proper" cd markers, hence making the file useless, however the... (1 Reply)
Discussion started by: saint65
1 Replies

5. Shell Programming and Scripting

Is there a way to recover files deleted using rm command???

Hi All, I just mistakingly deleted some files using rm command.Is there a way to get it back?i work on Solaris 10 Thanks, Kumar (1 Reply)
Discussion started by: kumarsaravana_s
1 Replies

6. UNIX for Dummies Questions & Answers

How to test for a specific file size

Hello, In my shell program, I need to test for a specific size of a text file before it can be imported into an oracle table. If the size is less than that number, my program should stop processing. What is the correct command to do this test? Thanks! (1 Reply)
Discussion started by: GEBRAUN
1 Replies

7. AIX

recover deleted files

How to recover deleted files in AIX ? (1 Reply)
Discussion started by: vjm
1 Replies

8. UNIX for Dummies Questions & Answers

Recover deleted files

Is there a Unix tool, like in Novell, to recover accidentally deleted files? (2 Replies)
Discussion started by: kuultak
2 Replies
Login or Register to Ask a Question