LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-11-2006, 11:58 AM   #1
crewblunts
Member
 
Registered: Jan 2004
Location: Connecticut, USA
Distribution: Slackware & Ubuntu
Posts: 53

Rep: Reputation: 15
problem with if statement in bash script


I am getting an error, unexpected token near `fi' with this script.
all the files in question exist.
Code:
#!/bin/bash

exec < files.txt
while read i
do
        if [ mp3info "$i" ]
                cat "$i" >> badFiles.txt
        fi
done
thanks in advance,

Phil V
 
Old 03-11-2006, 12:14 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
Quote:
Originally Posted by crewblunts
I am getting an error, unexpected token near `fi' with this script.
all the files in question exist.
Code:
#!/bin/bash

exec < files.txt
while read i
do
        if [ mp3info "$i" ]
                cat "$i" >> badFiles.txt
        fi
done
thanks in advance,

Phil V
Try this:

Code:
#!/bin/bash

exec < files.txt
while read i
do
        if [ mp3info "$i" ]; then
                cat "$i" >> badFiles.txt
        fi
done
 
Old 03-11-2006, 12:24 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
or better:
Code:
...
  if mp3info "$i"
  then
...
 
Old 03-11-2006, 12:38 PM   #4
crewblunts
Member
 
Registered: Jan 2004
Location: Connecticut, USA
Distribution: Slackware & Ubuntu
Posts: 53

Original Poster
Rep: Reputation: 15
Thank you both. I don't know how i missed 'then'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
bash statement os2 Programming 2 03-20-2005 10:13 PM
how to close 'else' statement block in bash script servnov Linux - General 9 11-12-2004 03:53 PM
Bash script problems with "if" statement adz Programming 2 05-22-2004 03:34 AM
Need help adding an IF / ELSE statement to my Bash Script Relix Linux - General 1 08-01-2002 02:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration