Welcome
Welcome to refracta

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

label partition

If it's not on-topic, it's in here.

label partition

Postby meandean » Sat Nov 10, 2012 4:41 am

I was thinking of doing this
Code: Select all
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?
User avatar
meandean
 
Posts: 392
Joined: Wed Mar 09, 2011 5:16 am

Re: label partition

Postby nadir » Sat Nov 10, 2012 6:43 am

Have a look if this may help:
[email protected]:~/Temp
$ cat tester.sh
Code: Select all
#!/usr/bin/env bash

echo ${1:5}

exit 0


reslut:
Code: Select all
$ 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).)
So i herd u liek mudkip?
User avatar
nadir
 
Posts: 1160
Joined: Wed Mar 09, 2011 4:18 am
Location: here

Re: label partition

Postby fsmithred » Sat Nov 10, 2012 11:53 am

more bash builtin...
Code: Select all
echo ${1##*/}


or with an external command...
Code: Select all
echo $(basename $1)


Edit: You could also do something like this:
Code: Select all
echo some-text_${1##*/}_or-some-text-here
User avatar
fsmithred
 
Posts: 2101
Joined: Wed Mar 09, 2011 9:13 pm

Re: label partition

Postby meandean » Sat Nov 10, 2012 3:06 pm

mucho better and saner....

thanks guys!!!
User avatar
meandean
 
Posts: 392
Joined: Wed Mar 09, 2011 5:16 am


Return to General Nonsense

Who is online

Users browsing this forum: No registered users and 0 guests

cron
suspicion-preferred