|
|
|
|
#1 |
|
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 Thanks in advance, L.
__________________
FreeSMUG-Free/opensource Sw Mac User Group |
|
|
|
|
|
#2 | |||||||||||||||||||||||
|
Moderator
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#3 |
|
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" 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. |
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
Moderator
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Moderator
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#7 |
|
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. |
|
|
|
|
|
#8 | |||||||||||||||||||||||
|
Moderator
Join Date: Jan 2002
Location: Montreal
Posts: 29,448
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#9 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: Apr 2004
Location: Milan, Italy
Posts: 72
|
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 |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|