I’m writing a quick shell script to build and execute my programs in one fell swoop.
I’ve gotten that part down, but I’d like to include a little if/else to catch bad extensions – if it’s not an .adb (it’s an Ada script), it won’t let the rest of the program execute.
My two-part question is:
- How do I grab just the extension? Or is it easier to just say
*.adb? - What would the if/else statement look like? I have limited experience in Bash so I understand that’s a pretty bad question.
Thanks!
There are ways to extract the extension, but you don’t really need to:
(The trouble with extracting the extension is that you’d have to define what you mean by “extension”. What is the extension of a file named
foo? How about a file namedreport.2012.01.29? So general-purpose extension-extracting code is tricky, and not worth it if your goal is just to confirm that file has a specific extension.)