Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
add comment

marked as duplicate by jasonwryan, enzotib, Mat, Gilles, Michael Mrozek Jan 15 '12 at 18:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.