Shell grammar question: logical OR in test


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell grammar question: logical OR in test
# 1  
Old 10-29-2012
Shell grammar question: logical OR in test

Hi,
I am trying to check if two input files exist before the rest of the scripts is run. Following is the code that I have but it gives me syntax error.

Code:
if [ ! -f /lv8/diamond/shprod/data/hcfadata.dat || ! -f /lv8/diamond/shprod/data/PDPhcfadata.dat  ]
then
echo "File not found"
else
echo "File found"
fi


Last edited by radoulov; 10-29-2012 at 02:40 PM.. Reason: Title addjusted.
# 2  
Old 10-29-2012
try with [[ ]]

Code:
if [[ ! -f /lv8/diamond/shprod/data/hcfadata.dat || ! -f /lv8/diamond/shprod/data/PDPhcfadata.dat  ]]

# 3  
Old 10-29-2012
Code:
if [ ! -f /lv8/diamond/shprod/data/hcfadata.dat ] || [ ! -f /lv8/diamond/shprod/data/PDPhcfadata.dat ]

# 4  
Old 10-29-2012
Code:
[ ! -f /lv8/diamond/shprod/data/hcfadata.dat -o ! -f /lv8/diamond/shprod/data/PDPhcfadata.dat  ]

or:

Code:
[ ! -f /lv8/diamond/shprod/data/hcfadata.dat ] || [ ! -f /lv8/diamond/shprod/data/PDPhcfadata.dat  ]

or (not standard):

Code:
[[ ! -f /lv8/diamond/shprod/data/hcfadata.dat || ! -f /lv8/diamond/shprod/data/PDPhcfadata.dat  ]]

This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is Rule 7 of POSIX shell grammar rules written correctly?

The POSIX shell standard grammar rules are at Shell Command Language I am trying to understand Rule 7 and I don't. I think there may be some mistakes there. I am not complaining about the standard; rather, I am concerned that my perception is wrong, and I don't understand something important.... (3 Replies)
Discussion started by: Mark_Galeck
3 Replies

2. UNIX for Dummies Questions & Answers

Logical OR in shell script

I have code as follows to perform some validations on C++ and Javascript files: if || || ; then However, when I want to add other extensions as well, say "py" or "sql", then the repeated OR starts to look contrived. I know I can use the -o operator to abbreviate the code a little bit, but... (14 Replies)
Discussion started by: figaro
14 Replies

3. Shell Programming and Scripting

Logical expression in POSIX compliant Korn Shell

Hi, i want to check if a variable var1 is not a or b or c pseudo code: If NOT (var1 = a or var1 = b or var1 = c) then ... fi I want to use POSIX complaint Korn shell, and for string comparison For the following code, logical.sh #!/usr/bin/ksh var="j" echo "Var : $var" if ! { || ||... (12 Replies)
Discussion started by: ysrini
12 Replies

4. Shell Programming and Scripting

nested logical expression in bash shell

Please tell me how to nest logical expressions in bash. I would like to nest logical expressions for arguments of the "test" command on bash. The following pseudo-code shows my intention. // pseudo code if (exp1 AND (exp2 OR exp3)) { Output true; } else { Output false; } ... (11 Replies)
Discussion started by: LessNux
11 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. Shell Programming and Scripting

Logical AND in shell commands

Hi:confused:, I have a file that contains : +-----------------------------------------------------------------------------+ LABEL: super1_fix EFIX FILES: 1 ABSTRACT: epkg for touch command PRE-REQUISITES: no PACKAGER VERSION: 7 REBOOT REQUIRED: no BUILD BOOT... (4 Replies)
Discussion started by: vijaya2006
4 Replies

7. AIX

question about a 'test' command

Hi all, I have the following script.Can somone explain what it does.Thanks in advance. if test $# -lt 1 then echo "Message" exit 1 fi (2 Replies)
Discussion started by: sam_78_nyc
2 Replies

8. AIX

AIX Logical Volume Question

Hi All, There is AIX server which has 2 internal disks running the OS and 8 external disks on a RAID array with RAID 5. My question - is there a way to check which are the logical volumes and file system configured on this RAID array (2 Replies)
Discussion started by: rramanuj
2 Replies

9. UNIX for Advanced & Expert Users

Logical Volume Manager question

After creating a make recover tape on a TAC-4 9000/770, the system lost three of five volume groups from the /etc/lvmtab. What would be the best way to recreate the volume groups in the lvmtab? (1 Reply)
Discussion started by: spawarrior
1 Replies
Login or Register to Ask a Question

Featured Tech Videos