Test file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Test file
# 1  
Old 10-04-2016
Test file

Hi,

I try to test 3 files,
Code:
#!/bin/bash
if  [ ! -f "$tf3" -a -f "$tf1" -a -f "$tf2" ];
then
        echo "ok"
else
        echo "ko"

It works partially, but I want that the output tell me "ok" only if the three files doesn't exist. Smilie
# 2  
Old 10-04-2016
If you change:
Code:
if  [ ! -f "$tf3" -a -f "$tf1" -a -f "$tf2" ];

to:
Code:
if [ ! -f "$tf3" -a ! -f "$tf1" -a ! -f "$tf2" ];

it would work on some systems. To work with any bash, the following should work:
Code:
if [ ! -f "$tf3" ] && [ ! -f "$tf1" ] && [ ! -f "$tf2" ]

but ALL of these will still leave you with a syntax error unless you also add another line at the end of your script:
Code:
fi

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 10-04-2016
I have the same problem, If tf3, is missing the output tell me "ok", but I want that when there are three missing files

---------- Post updated at 05:12 AM ---------- Previous update was at 05:00 AM ----------

It reacts like an "OR"

Last edited by Arnaudh78; 10-04-2016 at 07:08 AM..
# 4  
Old 10-04-2016
Please look closely at what I suggested in post #2. Note that you need ! -f file for all three tests; while your code only had one exclamation point.
# 5  
Old 10-04-2016
Yes, I modified in :
Code:
if [ ! -f "$tf3" ] && [ ! -f "$tf1" ] && [ ! -f "$tf2" ]
then
echo "ok"
else
echo "ko"
fi

But that's the same, If only tf3 is missing the output told me "ok" then I wish it told "ko"

---------- Post updated at 05:43 AM ---------- Previous update was at 05:38 AM ----------

Maybe the solution is to put tf1,tf2,tf3 in an array and to test the array ? is this the good way?
# 6  
Old 10-04-2016
Please show us how you defined and exported the variables tf1, tf2, and tf3 before executing your if statement!
# 7  
Old 10-04-2016
Quote:
Originally Posted by Don Cragun
Please show us how you defined and exported the variables tf1, tf2, and tf3 before executing your if statement!
Code:
tf1="/home/user/script/test1"
tf2="/home/user/script/test2"
tf3="/home/user/script/test3"


Last edited by rbatte1; 10-04-2016 at 10:27 AM.. Reason: Added CODE tags
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

2. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

3. Shell Programming and Scripting

Problem in test file operator on a ufsdump archive file mount nfs

Hi, I would like to ask if someone know how to test a files if exist the file is a nfs mount ufsdump archive file.. i used the test operator -f -a h almost all test operator but i failed file1=ufs_root_image.dump || echo "files doesn't exist && exit 1 the false file1 is working but... (0 Replies)
Discussion started by: jao_madn
0 Replies

4. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

5. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

6. UNIX for Dummies Questions & Answers

Test for file

I have a script that performs certains functions is a file exists in the specified directory: if then How can you do the reverse of this, basically an "if file does not exist"? dstins (6 Replies)
Discussion started by: dstinsman
6 Replies
Login or Register to Ask a Question