If it's not on-topic, it's in here.
Post a reply
meandean

- meandean
- Posts: 392
- Joined: Wed Mar 09, 2011 5:16 am

## label partition

Sat Nov 10, 2012 4:41 am

I was thinking of doing this

Code:
  `echo $1 > labelfile
  e2label $1 `sed 's ..... ' labelfile`
  rm labelfile`

to set the label for $1 to $1 without the first five characters
for example if $1 is /dev/sda3 then the partition label for /dev/sda3 will be sda3
whats a better way?
nadir

- nadir
- Posts: 1160
- Joined: Wed Mar 09, 2011 4:18 am
- Location: here

## Re: label partition

Sat Nov 10, 2012 6:43 am

Have a look if this may help:
[email protected]
:~/Temp
$ cat tester.sh

Code:
  `#!/usr/bin/env bash
  echo ${1:5}
  exit 0`

reslut:

Code:
  `$ bash tester.sh 12345foo
  foo`

The 1 is from $1, the :5 means from char number 5. :5:7 would be from 5-7... :0:3 would be the first three...
in case that was not clear (i gues it was clear, but ${1} is a bit confusing to me, and adding the colon doesn't make it better.
If the variable wouldn't be $1 but, say, $answer, it is more clear, i think:
echo ${answer:5}
or:
echo ${answer:0:3}
btw and PS: I had to look it up in my example code myself. I don't know such things out of box. (I use it when asking a user if the script shall go on and i only care if he/she gives y or not y (be it y, yes, yaba-duh or whatever).)
fsmithred

- fsmithred
- Posts: 2101
- Joined: Wed Mar 09, 2011 9:13 pm

## Re: label partition

Sat Nov 10, 2012 11:53 am

more bash builtin...

Code:
  `echo ${1##*/}`

or with an external command...

Code:
  `echo $(basename $1)`

Edit: You could also do something like this:

Code:
  `echo some-text_${1##*/}_or-some-text-here`

meandean

- meandean
- Posts: 392
- Joined: Wed Mar 09, 2011 5:16 am

## Re: label partition

Sat Nov 10, 2012 3:06 pm

mucho better and saner....
thanks guys!!!
Post a reply
Jump to:

Powered by phpBB © phpBB Group.

phpBB Mobile / SEO by Artodia.