Created
March 29, 2019 07:19
-
-
Save tralston/8fbce4cc26ae72fd86d25f201692994f to your computer and use it in GitHub Desktop.
Choose among multiple similar commands in bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# If the functionality of a GNU command (vs BSD) is needed, instead of checking for $OSTYPE, check if command is installed. | |
# This method isn't perfect, because you could have the case where the preferred command isn't installed when you expect it to be | |
# (e.g. Mac has no gdate installed). Perhaps in combination with $OSTYPE for better coverage. | |
# This checks if gdate is installed (likely beacuse running in a Mac environment). If not, use the normal date command. | |
DATE=$(type -p gdate date | head -n 1) | |
# Execute the command | |
$DATE +%Y%m%d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment