command line - How do I remove the file suffix and path portion from a path string in Bash? -
given string file path such "/foo/fizzbuzz.bar", how use bash extract "fizzbuzz" portion of said string?
here's how # , % operators in bash.
$ x="/foo/fizzbuzz.bar" $ y=${x%.bar} $ echo ${y##*/} fizzbuzz ${x%.bar} ${x%.*} remove after dot or ${x%%.*} remove after first dot.
example:
$ x="/foo/fizzbuzz.bar.quux" $ y=${x%.*} $ echo $y /foo/fizzbuzz.bar $ y=${x%%.*} $ echo $y /foo/fizzbuzz documentation can found in bash manual. ${parameter%word} , ${parameter%%word} trailing portion matching section.
Comments
Post a Comment