MX & MEPIS Community Forum

Linux operating systems based on Debian Stable
View unanswered posts | View unsolved topics | View active topics |

Reply to topic  [ 3 posts ] 
Shell Script Question [OR] 
Author Message
Forum Regular
Forum Regular
User avatar

Joined: Thu Jul 13, 2006 6:35 pm
Posts: 236
Has thanked: 25 times
Have thanks: 13 times
Post # 296899
Post Shell Script Question [OR]
The following code executes correctly:

# Remove old recording before recording new
if [ -f "$HOME/CBC-Radio/World-Report/incomplete/world-rpt" ]; then
if [ -e "$HOME/CBC-Radio/World-Report/$DATE.mp3" ]; then
rm $HOME/CBC-Radio/World-Report/*.mp3

Yet when I add the OR logical operator the code fails.

# Remove old recording before recording new
if [[ -f "$HOME/CBC-Radio/World-Report/incomplete/world-rpt" ] -o [ -f "$HOME/CBC-Radio/World-Report/incomplete/world-at-6"]]; then
if [ -e "$HOME/CBC-Radio/World-Report/$DATE.mp3" ]; then
rm $HOME/CBC-Radio/World-Report/*.mp3

./ line 13: syntax error in conditional expression
./ line 13: syntax error near `]'
./ line 13: `if [[ -f "$HOME/CBC-Radio/World-Report/incomplete/world-rpt" ] -o [ -f "$HOME/CBC-Radio/World-Report/incomplete/world-at-6"]]; then'

I can't find the syntax error, perhaps someone with more experience or younger eyes could point out the error of my ways ...

Thanks in advance for any advice or suggestions offered.


Never eat more than you can lift." --Miss Piggy

Tue Mar 06, 2012 1:57 pm
User avatar

Joined: Wed Jul 12, 2006 2:17 pm
Posts: 12484
Location: Rochester NY
Has thanked: 1207 times
Have thanks: 2056 times
Post # 296900
Post Re: Shell Script Question [OR]
Looks like you need to remove two brackets.


or (logical)

if [ $condition1 ] || [ $condition2 ]
# Same as:  if [ $condition1 -o $condition2 ]
# Returns true if either condition1 or condition2 holds true...

if [[ $condition1 || $condition2 ]]    # Also works.
# Note that || operator not permitted within [ ... ] construct.

EDIT: I am not a shell script expert, I just Googled the man page for bash shell scripts.

Forum Rules
Guide - How to Ask for Help


Laptop: Acer V5-572G: Intel i5, 12 GIG mem, Intel graphics, SanDisk SSD, 256GB
Virtualbox: Windows 7
Desktop: MX-15- 64, AMD A8 7600 FM2+ CPU R7 Graphics, fglrx driver, 8 GIG Mem. Samsung EVO SSD 250 GB

Tue Mar 06, 2012 2:06 pm
Forum Regular
Forum Regular

Joined: Sun Dec 09, 2007 4:19 am
Posts: 573
Has thanked: 25 times
Have thanks: 24 times
Post # 297123
Post Re: Shell Script Question [OR]
I thought it might be the semi colon after the double brackets

Sun Mar 11, 2012 12:02 am
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.