Need end of vari. string value. (REALLY SOLVED)
Need end of vari. string value. (REALLY SOLVED)
I'm using a lanpup.cfg file to feed values to my setup script, looks like:
SERV=160SEA
SMBHOME=PUPPYPC
PW=guest
USRMODE=file
I need to get the value after the "=", a simple thing, except for me that is.
SERV=`cat /sbin/lanpup.cfg | grep -i "SERV=" | sed s/^.*$//`
______________________________________________^
Can't see how to cut the first part off, what goes above here?
Or is there a better way to do it? The wanted segment is unknown in length, I'm stumped.
In VB to get the end of the SERV= string would be: S = Right$(String, Len(String) - 5).
Quote by Jeremy Anderson:
"There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence."
SERV=160SEA
SMBHOME=PUPPYPC
PW=guest
USRMODE=file
I need to get the value after the "=", a simple thing, except for me that is.
SERV=`cat /sbin/lanpup.cfg | grep -i "SERV=" | sed s/^.*$//`
______________________________________________^
Can't see how to cut the first part off, what goes above here?
Or is there a better way to do it? The wanted segment is unknown in length, I'm stumped.
In VB to get the end of the SERV= string would be: S = Right$(String, Len(String) - 5).
Quote by Jeremy Anderson:
"There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence."
Last edited by sunburnt on Fri 02 Dec 2005, 05:30, edited 1 time in total.
Guest; what you've said makes perfect sense, I've not tried it yet, but it looks good.
MU; I had to stare at it for about 10 mins. before I saw what was going on.
The "s/^.*=/" I got, but it took awhile till I saw how that was being erased by "//", leaving only the last part.
It'll take awhile till the chaos logic has realigned my brain synapses from the M$ world, MANY THANKS.
MU; I had to stare at it for about 10 mins. before I saw what was going on.
The "s/^.*=/" I got, but it took awhile till I saw how that was being erased by "//", leaving only the last part.
It'll take awhile till the chaos logic has realigned my brain synapses from the M$ world, MANY THANKS.
Actually the easiest way to get the 'value' for all the name/value pairs is:
Or if you want just for one value (assuming that the name starts at the begining of the line)
Explanation
cut : splits an input line into fields
-d : specifies the delimiter. In this case "="
-f : specifies the field number. In this case the second field.
Code: Select all
cut -d= -f2 /sbin/lanpup.cfg
Code: Select all
grep "^SERV=" /sbin/lanpup.cfg | cut -d= -f2
cut : splits an input line into fields
-d : specifies the delimiter. In this case "="
-f : specifies the field number. In this case the second field.
I went to bed yesterday thinking that we are getting it all wrong.
If you need to know the values of all those variables from within a script, Why not executing the cfg file as if it was a script? e.g.:
If you need to know the values of all those variables from within a script, Why not executing the cfg file as if it was a script? e.g.:
Code: Select all
sh /sbin/lanpup.cfg
echo $SERV
echo $SMBHOME
- Lobster
- Official Crustacean
- Posts: 15522
- Joined: Wed 04 May 2005, 06:06
- Location: Paradox Realm
- Contact:
How to create a shell script
We could do with a ScriptTutorials page on the wiki
incorporating or cutting / pasting from here:
http://puppylinux.org/wikka/AzBash
http://puppylinux.org/wikka/AshSh
with links such as
http://www.grymoire.com/Unix/Sed.html
and a wink video on "How to create a shell script"
incorporating or cutting / pasting from here:
http://puppylinux.org/wikka/AzBash
http://puppylinux.org/wikka/AshSh
with links such as
http://www.grymoire.com/Unix/Sed.html
and a wink video on "How to create a shell script"