POSIX shell 允許變數再回傳值之前進行 triming 動作。
Syntx:
${variable#pattern} #: Trim the value from the left ${variable%pattern} %:Trim the value from the right
sample:
#!/bin/sh FULLPATH=/test/shell/sample/test.data FILENAME=${FULLPATH##*\/} PATHNAME=${FULLPATH%\/*} echo "fullpath=${FULLPATH}" echo "pathname=${PATHNAME}" echo "filename=${FILENAME}"
output:
fullpath=/test/shell/sample/test.data
pathname=/test/shell/sample
filename=test.data
沒有留言:
張貼留言