Skip to content

Instantly share code, notes, and snippets.

@cpelley
Last active November 4, 2016 08:45
Show Gist options
  • Select an option

  • Save cpelley/34a79c67c92fd978c774f7437284f3e5 to your computer and use it in GitHub Desktop.

Select an option

Save cpelley/34a79c67c92fd978c774f7437284f3e5 to your computer and use it in GitHub Desktop.
Commandline utility to split the extension from the given file.
#!/bin/bash
# Function to return the extension of a file
# Returning the extension as a string (e.g. ".txt") or false otherwise.
#
# Add this file to your PATH to make available and ensure that it has
# executable privileges.
#
# Example usage:
# splitext <file>
[[ "${1}" = *.* ]] && echo ".${1##*.}" || false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment