3 ms·
My favorite: basename Returns just the filename plus extensions e.g. basename a/b/c/d/foo.php returns foo.php Very useful for shell scripting.
by dkns 9y ago
My favorite: basename
Returns just the filename plus extensions e.g.
basename a/b/c/d/foo.php
returns foo.php
Very useful for shell scripting.
- deleted 9y ago[deleted]
- chriswarbo 9y agoIt can also strip off a given suffix, if it appears: $ basename a/b/c/d/foo.php .php foo The complement to basename is dirname: $ dirname a/b/c/d/foo.php a/b/c/d
- fpoling 9y agoWith shell one can just use "${path_var##*/}" to get the base name from the string stored in $path_var. This also works if $path_var is just a base name already without any slashes. EDIT: fixed the substitution.
- josefx 9y ago> With shell one can just use "${path_var##*/}" The reason I use python whenever I need something "shell" like. Cryptic symbol salad that makes code golf fanatics green with envy.