Operating System - HP-UX
1830930 Members
2316 Online
110017 Solutions
New Discussion

Re: qustion:ask the usage of ${DISK##*/} in a shell??

 
小马哥_1
Contributor

qustion:ask the usage of ${DISK##*/} in a shell??

qustion:ask the usage of ${DISK##*/} in a shell??


there is a shell:

echo "please input device name : \c"
read DISK
echo "${DISK##*/}"


after run ,I input /dev/rdsk/c2t6d0
the output is c2t6d0


I don't know the usage of ${DISK##*/},please help me explain it?? thank you!
3 REPLIES 3
Adam Garsha
Valued Contributor

Re: qustion:ask the usage of ${DISK##*/} in a shell??

${parameter##pattern}
If the shell pattern matches the beginning of
the value of parameter, the value of this
substitution is the value of the parameter
with the matched portion deleted; otherwise
the value of this parameter substituted. In
the former case, the smallest matching
pattern is deleted; in the latter case, the
largest matching pattern is deleted.
Bill Hassell
Honored Contributor

Re: qustion:ask the usage of ${DISK##*/} in a shell??

This is an example of using the (much more efficient) shell to replace an external command, in this case, the basename command. These are equivalent:

DISK=/dev/rdsk/c2t6d0
basename $DISK
echo "${DISK##*/}"

Both methods remove everything from the rightmost "/" to the beginning of the string. Similarly, there is a dirname command and an equivalent shell construct that will return only the directory portion:

DISK=/dev/rdsk/c2t6d0
dirname $DISK
echo "${DISK%/*}"


Bill Hassell, sysadmin
小马哥_1
Contributor

Re: qustion:ask the usage of ${DISK##*/} in a shell??

thank you very muchï¼