Ubuntu Breezy 5.10 (don't suggest an upgrade - it works!)

I'm trying to set up a script which updates some software on the hard drive from a directory on a USB Flash drive.

After I've plugged in the USB drive and seen it recognised by automount:

ls -l /vol/USBDISKB

OK - shows me the directory and files.


#!/bin/bash if [ -d /vol/USBDISKB ]; then echo "Found USB drive" else echo "Not found: USB drive!" fi

doesn't see the USB drive. :-((

P.S. I tried to edit so it looks like code. Really.

18/04/10 08:54 GMT Well! I don't know are am pretty stupid but I don't seem able to add a comment in response. All I seem able to do is edit my original post :(

The obvious typos you can put down to my newbieness.

If you are interested on following this question there has developed a much bigger thread here:

LQ Thread

asked 16 Apr '10, 10:55

fopetesl's gravatar image

accept rate: 0%

edited 07 May '10, 19:17

rschuler's gravatar image



One thing - if you are running such an old version of Ubuntu, at least subscribe to security mailing lists so you can keep the holes from being too great.

(16 Apr '10, 14:24) XavierP

Please accept an answer so the question/answer can be finished. Or provide more details so we can help.

(20 Apr '11, 13:45) rfelsburg ♦

Try this:

if ls /vol/USBDISKB 2>/dev/null
   echo "Found USB drive"
   echo "Not found: USB drive!"

answered 16 Apr '10, 12:50

jlliagre's gravatar image

accept rate: 50%

There should be a semicolon before the else.

This works in my rig

if [ -d /media/K4G ]; then echo "it is"; else echo "is not"; fi


answered 17 Apr '10, 16:38

LiquidPaper's gravatar image

accept rate: 0%

Semicolons are only necessary when putting everything on a single line. The above script will work just fine, although, the ! may be interpreted as strangely depending on the verison of bash. Since there aren't any variables or expansion needed, I would recommend enclosing that particular string in single quotes.

(01 Mar '13, 13:55) rfelsburg ♦

The script you've got here won't work because it is missing semi-colons, as another poster suggested:

if [ -d /vol/USBDISKB ]; then echo "Found USB drive"; else echo "Not found: USB drive!"; fi

If you are going to put it into a script and not run it from the command line, then you can break it up so it is easier to read:


if [ -d /vol/USBDISKB ]
    echo "Found USB drive" 
    echo "Not found: USB drive!"

Note that this way, you don't need to include the semi-colons, because multiple commands aren't on the same line.

Good luck,



answered 18 Apr '10, 03:16

jeddaniels's gravatar image

accept rate: 0%

You can enter a multiline command at the shell prompt. The shell will prompt with $PS2 until the command is complete:

$ if [ -d /vol/USBDISKB ]
> then
>   echo "Found USB drive"
> else
>   echo "Not found: USB drive!"
> fi
Not found: USB drive!

The '!' in double quotes might cause a problem due to the ridiculous practice of using a printing character for something other than printing the character. I prevent it by setting $histchars to the emptry string in ~/.bashrc


answered 01 Mar '13, 06:44

cfajohnson's gravatar image

accept rate: 0%

edited 01 Mar '13, 06:48

Does it have to be a bash script? Maybe a PERL script would work better?


answered 17 Apr '10, 03:29

BaldGuyKen's gravatar image

accept rate: 0%

i think try while condition is the best for your case


answered 22 Apr '10, 07:19

Network%20Systems%20Engineer's gravatar image

Network Syst...
accept rate: 16%

Most of the above examples don't work, because of the !

It seems that putting the ! in quotes gives it a special meening, but outside of quotes is a regular charecter. (that seems backwards, maybe I am going mad)


answered 04 May '11, 12:04

daves%20dad's gravatar image

daves dad
accept rate: 0%

Why not just upgrade to the latest LTS version, 10.04.2LTS?


answered 05 May '11, 10:07

Ron's gravatar image

Ron ♦
accept rate: 13%

There are a couple of solutions to the exclamation mark:
1) put the string in single quotes:
echo 'Hello!'
2) put a space after the exclamation mark or no quotes
echo "hello! " ; echo Hello!

For some strange reason, bash will not delete a backslash that quotes the exclamation mark when inside double quotes.


answered 02 Mar '13, 19:57

darkonc's gravatar image

accept rate: 0%

Are you sure /vol/USBDISKB is the mountpoint? Try this to see:

mount | grep USBDISKB

Another option is to use the mountpoint command instead of brackets:

if mountpoint -q /vol/USBDISKB; then echo "it is"; else echo "is not"; fi

Or just:

mountpoint /vol/USBDISKB

answered 07 Nov '13, 07:05

KenJackson's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 16 Apr '10, 10:55

Seen: 4,476 times

Last updated: 07 Nov '13, 07:05

powered by OSQA