Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with 'or' in script

Status
Not open for further replies.

longhair

MIS
Feb 7, 2001
889
0
0
US
afternoon all,
with help from p5wizard, earlier, i almost have a script finished but am having an issue with some 'or' phrasing.
code as follows:
Code:
cd /dira                                                             
rm dsnodotb.txt                                                                 
rm dsinscrpt.txt                                                                
for file in $(ls *.a 2>/dev/null)                                               
do                                                                              
  base=$(basename $file .a)                                                     
  if [ ! -f /dira/$base.b ] -o [ ! -f /dirb/$base.b ]                                                                         
  then                                                                          
   echo $file: $base.b does not exist >> dsnodotb.txt                           
  fi                                                                            
done                                                                            
cat /dira/dsnodotp.txt | while read dotr dotb tmp                    
do                                                                              
find /dirc -type f -print |xargs grep $dotb >> /dirb/dsinscrpt.txt                                                                     
done
what i need to do is execute the echo if $base.b is not in dira or dirb
i have tried th -o for 'or' as posted above also || but when $base.b does not exist in dira but does exist in dirb i still get the output into dsnodotb.txt.
any suggestions?
regards,
longhair
 
I'm not at a term right now, but try:

before...
if [ ! -f /dira/$base.b ] -o [ ! -f /dirb/$base.b ]

after...
if [ ! -f /dira/$base.b -o ! -f /dirb/$base.b ]
 
pavNell,
thanks, but no go.
removing the inner ']' and '[' returns everything - even items that the test should have excluded.
regards,
longhair
 

Shouldn't the test be "and" which is '-a'?

Isn't the question, "does this dot 'a' file have a dot 'b' in either of these directories?"

 
try this (positive test)

...
if [ -f /dira/$base.b -o -f /dirb/$base.b ]
then
:
else
echo $file: $base.b does not exist >>dsnodotb.txt
fi
...



HTH,

p5wizard
 
Hi

Do as the guys suggested above, I show only the correction of your code :
Code:
if [ ! -f /dira/$base.b ] [red]||[/red] [ ! -f /dirb/$base.b ] 
[gray]...[/gray]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top