Short Notes on Bash

From PaskvilWiki
Revision as of 21:16, 1 June 2012 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Extensions and File Name

$ fullname='/tmp/file.tar.gz'
$ filename=$(basename $fullname)
$ echo ${filename##*.}
>> gz
$ echo ${filename#*.}
>> tar.gz
$ echo ${filename%.*}
>> file.tar
$ echo ${filename%%.*}
>> file

For more options and explanations, see Bash - Shell Parameters Expansion.