LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 06-13-2005, 08:20 AM   #1
GATTACA
Member
 
Registered: Feb 2002
Location: USA
Distribution: Fedora, CENTOS
Posts: 201

Rep: Reputation: 32
bash script problem


Hello.
I'm trying to write a bash script that first checks to see if my USB hard drive is mounted before moving some files over to it.

I thought this code should work but I keep getting an error message and the conditional doesn't execute properly.

I can't see my error can anyone help?

##############################################
## check to see if the USB 2.0 Drive is mounted
file="/home/user/some.file"
a=`cat /proc/mounts | cut -d' ' -f2 | grep /backup`
b="/backup"

if[ "x$a" != "x$b" ] then
echo -e "\nUSB drive is not mounted\n"
exit
else
echo -e "\nmv $file /backup/$file\n"
fi

echo -e "\n\nDone!\n\n"
#############################################


By the way here is the error I get after calling the script from the command line:

./test_script.sh: line 6: if[ x/backup != x/backup ]: No such file or directory

USB drive is not mounted


Any ideas anyone?

Thanks
 
Old 06-13-2005, 08:25 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
There's two problems in this line:
Code:
if[ "x$a" != "x$b" ] then
It should be:
Code:
if [ "x$a" != "x$b" ]; then    # Note space between if and [, and semicolon after ]
 
Old 06-13-2005, 09:54 AM   #3
GATTACA
Member
 
Registered: Feb 2002
Location: USA
Distribution: Fedora, CENTOS
Posts: 201

Original Poster
Rep: Reputation: 32
Thanks!

This is a dumb question but why does the spacing matter?
My scripts are usually in perl where this generally isn't an issue.
 
Old 06-13-2005, 09:59 AM   #4
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
It's because the test is actually run with a program called [ (really!) which is what you need to run. Without the space, your system was trying to run a program called if[ which doesn't exist.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 script problem fatbastard spice Linux - General 2 08-24-2005 02:15 AM
Problem with this bash script cantabile Programming 3 06-06-2005 05:31 PM
bash script problem cookie_ie Programming 3 03-23-2005 02:19 PM
bash script problem sorry99 Programming 2 09-20-2004 09:02 AM
Bash script problem kalleanka Programming 2 01-30-2004 11:59 AM


All times are GMT -5. The time now is 05:11 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration