Joined: Thu Jul 13, 2006 6:35 pm Posts: 204 Has thanked:18 times Have thanks:13 times
Post # 296899
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
richb
Administrator
Joined: Wed Jul 12, 2006 2:17 pm Posts: 8754 Location: Rochester NY Has thanked:582 times Have thanks:956 times
Post # 296900
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.
All times are UTC - 5 hours [ DST ] | It is currently Sat May 25, 2013 3:22 am
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