Bash parameter expansion

Lennart Sorensen lsorense-1wCw9BSqJbv44Nm34jS7GywD8/FfD2ys at public.gmane.org
Mon Aug 23 19:14:23 UTC 2010


On Sun, Aug 22, 2010 at 06:36:11PM -0400, Giles Orr wrote:
> With Debian's recent change to the way it handles device names at
> boot-up, I can't count on / being on sda anymore.  Today it's on sde,
> but what I've read suggests that that may change.  This messes up my
> automatic backup of the MBR, so I'm trying to figure out how to
> determine this value automatically.  What I've come up with so far is
> this:

That is a kernel change, not a Debian change.

> tmp="$(mount | grep [[:space:]]/[[:space:]])" ; tmp1=${tmp%% *};
> tmp2=${tmp1#/dev/} ; echo ${tmp2%%[0123456789]*}
> 
> Two questions: is there an easier way to determine this value without
> pulling it out of mount like that?   And: is there an easier way to do
> a string of Bash parameter expansions than assigning to multiple temp
> values like that?  Even if there's an simple answer for the first
> question I'd love an answer to the second as I've had to use that
> messy method several times.  (I know I can do this in awk or perl more
> easily: I'd like to stick to Bash here.)  Thanks in advance.

Best option is look at /dev/disk/by-*

Each disk will have a unique identifier (usually serial number based), so
you can do things based on that.  Much better than what you used to have.

For example:

/dev/disk/by-id/ata-WDC_WD2500JD-22HBB0_WD-WCAL72953808 -> ../../sdb

So simply using the consistent by-id names means not worriying about
which /dev/sd* it happens to be today.  It isn't your problem.

-- 
Len Sorensen
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list