Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rate Thread Display Modes
Old 01-13-2006, 07:02 AM   #1
leonida
Triple-A Player
 
Join Date: Apr 2004
Location: Milan, Italy
Posts: 72
usb device name as variable in a shell script

Sorry, I'm not very experienced with script.
Do you know how can I get usb device name as variable in a shell script (.command) that has to be run from device itself?

Ex:
Code:
cp /Volumes/<mydevice>/alpha /Volumes/<mydevice>/beta
where <mydevice> can change.

Thanks in advance, L.
__________________
FreeSMUG-Free/opensource Sw Mac User Group
leonida is offline   Reply With Quote
Old 01-13-2006, 09:00 AM   #2
hayne
Moderator
 
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
Quote:
Originally Posted by leonida
Sorry, I'm not very experienced with script.
Do you know how can I get usb device name as variable in a shell script (.command) that has to be run from device itself?

Ex:
Code:
cp /Volumes/<mydevice>/alpha /Volumes/<mydevice>/beta
where <mydevice> can change.

You aren't being very clear about what you want.
Or perhaps you just want to know how to create and use variables in a shell script. You would do it like this:

mydevice="the_name_of_the_device"
cp "/Volumes/$mydevice/alpha" "/Volumes/$mydevice/beta"

I assume from your example, that the "USB device" you are concerned with is actually a mounted disk drive. In that case, it's not really relevant that it is a USB device - what is relevant is that it is mounted under /Volumes.

Perhaps this Unix FAQ might be of help.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-13-2006, 09:15 AM   #3
leonida
Triple-A Player
 
Join Date: Apr 2004
Location: Milan, Italy
Posts: 72
I'm trying something like this
Allow .command files to determine working directory.
In your example I don't know the: "the_name_of_the_device"
I wish to get "the_name_of_the_device" as variable as I don't know it or as it could be changed.

At the moment with:
Code:
#!/bin/sh
here="`dirname \"$0\"`"
echo "cd-ing to $here"
I get this error
Code:
here="(dirname: bad interpreter: No such file or directoryin/sh
__________________
FreeSMUG-Free/opensource Sw Mac User Group

Last edited by leonida; 01-13-2006 at 09:18 AM.
leonida is offline   Reply With Quote
Old 01-13-2006, 09:26 AM   #4
hayne
Moderator
 
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
Quote:
Originally Posted by leonida
I get this error
Code:
here="(dirname: bad interpreter: No such file or directoryin/sh

I suspect that your script file is using something other than Unix end-of-line characters.
What editor are you using to create this script file?
See this Unix FAQ about the end-of-line character issue and recommendations for editors.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-13-2006, 09:36 AM   #5
leonida
Triple-A Player
 
Join Date: Apr 2004
Location: Milan, Italy
Posts: 72
Quote:
Originally Posted by hayne
What editor are you using to create this script file?

I'm using Smultron
__________________
FreeSMUG-Free/opensource Sw Mac User Group
leonida is offline   Reply With Quote
Old 01-13-2006, 09:42 AM   #6
hayne
Moderator
 
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
Quote:
Originally Posted by leonida
I'm using Smultron

Check the "line endings" preference in Smultron. I recommend setting it to force Unix line-endings.
There should also be a way to see what the line-endings are for a particular document.

Otherwise, try using the Perl script I supply in the line-endings section of that FAQ to fix the line-endings of your script file.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-13-2006, 10:04 AM   #7
leonida
Triple-A Player
 
Join Date: Apr 2004
Location: Milan, Italy
Posts: 72
Thanks, that was the problem, now I'm using nano.

Is there a way to get device name instead of dirname?
__________________
FreeSMUG-Free/opensource Sw Mac User Group

Last edited by leonida; 01-13-2006 at 10:11 AM.
leonida is offline   Reply With Quote
Old 01-13-2006, 10:19 AM   #8
hayne
Moderator
 
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
Quote:
Originally Posted by leonida
Is there a way to get device name instead of dirname?

You'll have to explain using more words to describe what you are trying to do.
Or maybe you are asking: "How do I find out the "/dev" entry that corresponds to a particular disk?" - if so, look at the output of the 'df' command.
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 01-13-2006, 06:56 PM   #9
leonida
Triple-A Player
 
Join Date: Apr 2004
Location: Milan, Italy
Posts: 72
Quote:
Originally Posted by hayne
You'll have to explain using more words to describe what you are trying to do.
Or maybe you are asking: "How do I find out the "/dev" entry that corresponds to a particular disk?" - if so, look at the output of the 'df' command.

Sorry I'm quite a newbie, and I'm not english speaking, and thanks a lot for your help.
I've solved my problem but I like to learn more.
I'm interested on how do I find out the "Volumes/<name_of_volume>" and use it as a variable.
Es:

Code:
here="<something that tell me the Volumes name>"
echo "My Volume name is $here"
__________________
FreeSMUG-Free/opensource Sw Mac User Group
leonida is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 06:27 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Site design © Mac Publishing LLC; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of Mac Publishing LLC.