MEPIS Community Forum

A Linux operating system 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: 225
Has thanked: 21 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
fi
fi

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
fi
fi


./tmp.sh: line 13: syntax error in conditional expression
./tmp.sh: line 13: syntax error near `]'
./tmp.sh: 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.

Tom

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


Tue Mar 06, 2012 1:57 pm
Profile
Administrator
User avatar

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

example:

Code:
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
Link to Wiki
Rich

Acer Laptop V5-572G: Intel i5, 12 GIG mem, nVidia GT720M/Intel integrated graphics
Mx-14 Symbiosis
Kubuntu 13.10, KDE 4.11.2


Tue Mar 06, 2012 2:06 pm
Profile
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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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:  
cron

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