Please note that LinuxExchange will be shutting down on December 31st, 2016. Visit this thread for additional information and to provide feedback.

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.

-BUT_

#!/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

fopetesl
1113
accept rate: 0%

edited 07 May '10, 19:17

rschuler's gravatar image

rschuler
77110

2

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:

#!/bin/bash
if ls /vol/USBDISKB 2>/dev/null
then
   echo "Found USB drive"
else
   echo "Not found: USB drive!"
fi
link

answered 16 Apr '10, 12:50

jlliagre's gravatar image

jlliagre
1513
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

link

answered 17 Apr '10, 16:38

LiquidPaper's gravatar image

LiquidPaper
12113
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:

#!/bin/bash
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:

#!/bin/bash

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

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

Good luck,

--jed

link

answered 18 Apr '10, 03:16

jeddaniels's gravatar image

jeddaniels
53115
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

link

answered 01 Mar '13, 06:44

cfajohnson's gravatar image

cfajohnson
213
accept rate: 0%

edited 01 Mar '13, 06:48

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

link

answered 17 Apr '10, 03:29

BaldGuyKen's gravatar image

BaldGuyKen
313
accept rate: 0%

i think try while condition is the best for your case

link

answered 22 Apr '10, 07:19

Network%20Systems%20Engineer's gravatar image

Network Syst...
2415
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)

link

answered 04 May '11, 12:04

daves%20dad's gravatar image

daves dad
1136
accept rate: 0%

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

link

answered 05 May '11, 10:07

Ron's gravatar image

Ron ♦
9361718
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.

link

answered 02 Mar '13, 19:57

darkonc's gravatar image

darkonc
1
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
link

answered 07 Nov '13, 07:05

KenJackson's gravatar image

KenJackson
5113
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

By RSS:

Answers

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

Tags:

×16
×16
×9
×2

Asked: 16 Apr '10, 10:55

Seen: 4,662 times

Last updated: 07 Nov '13, 07:05

powered by OSQA