0

Possible Duplicate:
How do ${0##/} and ${0%/} work?

0:root@SERVER:/ # 
0:root@SERVER:/ # serial=$(lscfg -vl hdisk1 | awk '/Serial Number/')
0:root@SERVER:/ # echo $serial                                      
Serial Number...............11BBGG11235
0:root@SERVER:/ #             
0:root@SERVER:/ # 
0:root@SERVER:/ # serial=${serial##*.}                              
0:root@SERVER:/ # echo $serial                                      
11BBGG11235
0:root@SERVER:/ # 

What does exaclty

serial=${serial##*.}

do? Can someone please explain it? It's hard to google it :D

LanceBaynes
  • 39,295
  • 97
  • 250
  • 349

1 Answers1

2

Its a parameter expansion in shell. For example:

serial=${serial##*.} -- this will get the value in the last field delimited by '.' seperator. Grab the most last '.' in the value and print the rest of the data.

parameter     result
-----------   ------------------------------
${NAME}       polish.ostrich.racing.champion
${NAME#*.}           ostrich.racing.champion
${NAME##*.}                         champion
${NAME%%.*}   polish
${NAME%.*}    polish.ostrich.racing



parameter     result
-----------   --------------------------------------------------------
${FILE}       /usr/share/java-1.4.2-sun/demo/applets/Clock/Clock.class
${FILE#*/}     usr/share/java-1.4.2-sun/demo/applets/Clock/Clock.class
${FILE##*/}                                                Clock.class
${FILE%%/*}
${FILE%/*}    /usr/share/java-1.4.2-sun/demo/applets/Clock

For more examples look at http://mywiki.wooledge.org/BashFAQ/073

Nikhil Mulley
  • 8,145
  • 32
  • 49