PDA

View Full Version : Shell script



bonzi
June 10th, 2010, 10:30 AM
I'm a N00b in shell scripting. What does this script do?
NUMJOB=${NUMJOB#*=}

DaithiF
June 10th, 2010, 11:19 AM
Hi,
it strips everything from the variable up to and including the first '=' sign.

so if NUMJOB was something=somevalue
then after the operation NUMJOB would be left with just somevalue

man bash to learn more (section Parameter Expansion)

bonzi
June 10th, 2010, 01:23 PM
Thanks you very much for the reply. I have one more question regarding sed

How do I get the string after teh 3rd occurance of :. In this case C1:EF:00
18:A9:05:C1:EF:00

trent.josephsen
June 10th, 2010, 01:35 PM
The version requiring no thought would be `awk -F: '{ print $4 }'` but if you wanted a bash-only version it will be more involved.

Trumpen
June 10th, 2010, 01:58 PM
$ foo=18:A9:05:C1:EF:00
$ echo ${foo#*:*:*:}
C1:EF:00

geirha
June 10th, 2010, 02:03 PM
# bash
$ IFS=: read -r -a array <<< '18:A9:05:C1:EF:00'
$ echo "${array[3]}"
C1
$ (IFS=:; echo "${array :3}")
C1:EF:00


Probably overkill for your case though. I'd go with Trumpen's solution.

bonzi
June 10th, 2010, 03:41 PM
Thank you all trent.josephsen (http://ubuntuforums.org/member.php?u=763491) solution woked perfectly for my scenario. Thanks once again