Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AquaMethod

macrumors member
Original poster
Jun 17, 2008
65
0
I'd like to create a bash script that would live on a USB thumb drive and copy over some files from that same USB drive, onto the Mac it's plugged into. How can I refer to the path the script is executing from, even if the name of the drive has changed or it's not mounted under /Volumes ?

I suppose it's possible to mess around with the $0 parameter, but will that work even if the script is created as a .command file, and run by the Finder?
 

AquaMethod

macrumors member
Original poster
Jun 17, 2008
65
0
Ah, that makes sense. (Not sure why I didn't think to search SO first...thanks for doing so)

So the cleanest solution would probably be

Code:
scriptPath=`dirname $0`

And then use $scriptPath from there one? Seems like that'll work.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.