bash: best way to get filename and extension using bash
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions, and this can be hazardous
Last edited by frenchn00b; 01-09-2010 at 01:01 PM.
There are likely a stack of ways to do the same; is there anything in particular you don't like about the way you have used above? You could use awk or sed too, but the way you used is probably no better or worse, unless you're considering the difference in nanoseconds that each particular method uses (time to do the operation), in which case cut is probably faster than awk but similar to sed.
Faster yet again, might be ${bash/substitution/substitution} if you are always using bash shell. Check the man page for details on this.
Last edited by GrapefruiTgirl; 01-09-2010 at 01:07 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.