Conditional OR in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Conditional OR in shell
# 8  
Old 04-25-2016
Quote:
Originally Posted by Scrutinizer
This could be simplified further still:
Code:
if ls -A "$apache_log_dir"/*.log "$jboss_log_dir"/*.log 1>/dev/null 2>&1; then

No, it can't. This script needs to continue if there is a matching file in either directory.
Code:
ls -A "$apache_log_dir"/*.log "$jboss_log_dir"/*.log 1>/dev/null 2>&1

will give a non-zero exit status if the match in either directory fails.
Code:
[[ $(ls -A $apache_log_dir/*.log $jboss_log_dir/*.log 2>/dev/null) ]]

will give a non-zero exit status only if neither directory contains a matching file.
This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 04-25-2016
SmilieYes you are 100% right .. It is testing a different thing and I never realized ls would return 1 if one of files is not present even if all the other ones are..


---
full shell solution (without line length limitations):
Code:
file_exists() {
  for _i do
    [ -e "$_i" ] && break
  done
}

if exists "$apache_log_dir"/*.log23 "$jboss_log_dir"/*.log


Last edited by Scrutinizer; 04-25-2016 at 08:40 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conditional Vlookup

Hi everyone, I need to replace values of column 2 array1 with values of column 2 array2 based on a lookup of column 4 value, but only return a value IF the values in column 1 of BOTH array1 and array2 match, otherwise keep original value in column 2 of array1. Both files are tab delimited... (2 Replies)
Discussion started by: Geneanalyst
2 Replies

2. UNIX for Beginners Questions & Answers

Conditional Split

Greetings, I need help in splitting the files in an efficient way while accommodating the below requirements . I am on AIX. Split condition Split the file based on the record type and the position of the data pattern that appears on the on the record type. Both record type and and the... (9 Replies)
Discussion started by: techedipro
9 Replies

3. Shell Programming and Scripting

How to append to array within conditional block in ksh/korn shell?

Hi, I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement. #!/bin/ksh echo "---------------------------------------------------" set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Discussion started by: sanzee007
2 Replies

4. Shell Programming and Scripting

Conditional search and delete using SED / Shell script

Hi, I want to perform a conditional search and remove my search string. Input string: "abcdaabcadgfaarstab" Character to search: "a" Condition: Remove all "a" in the input string except if it is "aa" Output string: "bcdaabcdgfaarstb" Can you please help me in this? (5 Replies)
Discussion started by: dominiclajs
5 Replies

5. Shell Programming and Scripting

Conditional Shell Statement

I want to add a conditional statement to a user's .profile file. I have a certain number of users that log in and use the rksh (Restricted Korn Shell). When they log in, it starts a certain program and when they exit this program, the system logs them out. When they are in this program, they can... (2 Replies)
Discussion started by: rjulich
2 Replies

6. Shell Programming and Scripting

Help on shell script conditional execution when CPU Idle > 60%

I need a shell script that will monitor a few conditions and not execute until the these conditions are met. The problem I'm having is that I can not perform a database snapshot (backup) of a sybaseIQ database unless the CPU Status Idle % is above 60% or the snapshot (backup) fails. If... (2 Replies)
Discussion started by: pancona99
2 Replies

7. Shell Programming and Scripting

conditional extracting

Hi, I need to extract lines based on some conditions as explained below: File format details: 1. each set starts with AAA only 2. number of columns is fixed 3. number of rows per set may vary (as one set is upto DDD - 4 rows) Now, i need to extract only the lines starting with AAA and... (2 Replies)
Discussion started by: prvnrk
2 Replies

8. Shell Programming and Scripting

If conditional

Hi, I am new to unix and shell scripting.In my script,there is a line using the "if" conditional - if && ; then do something Here "x" is a variable holding string value.If it is not equal to a comma or a string,only then I want to enter the "if" loop. But I am getting error while... (12 Replies)
Discussion started by: abhinavsinha
12 Replies

9. UNIX for Dummies Questions & Answers

If conditional

Hi, I am new to unix and shell scripting.In my script,there is a line using the "if" conditional - if && ; then do something Here "x" is a variable holding string value.If it is not equal to a comma or a string,only then I want to enter the "if" loop. But I am getting error while... (1 Reply)
Discussion started by: abhinavsinha
1 Replies

10. UNIX for Dummies Questions & Answers

conditional

conditional is not wworking can any one figure out what goes wrong xx1=`$ORACLE_HOME/bin/sqlplus -s apps/ostgapps1 2>/dev/null << EOF WHENEVER SQLERROR EXIT 1 set head off feedback off ; WHENEVER SQLERROR EXIT SQL.SQLCODE; select count(*) from CMS_INVOICE_ALL... (2 Replies)
Discussion started by: u263066
2 Replies
Login or Register to Ask a Question