Skip to content

Instantly share code, notes, and snippets.

@categulario
Last active May 19, 2018 15:33
Show Gist options
  • Save categulario/7bcd194ddf958b803124083390203cfd to your computer and use it in GitHub Desktop.
Save categulario/7bcd194ddf958b803124083390203cfd to your computer and use it in GitHub Desktop.
Convierte pesos a dólares y de regreso desde la consola
# Usage: usdtomxn 1
# Output: 19.9319
# Usage: mxntousd 19.9319
# Output: 1.0
#
# You'll need the jq command for this to run
# Vas a necesitar el comando jq para que esto jale
#
# https://stedolan.github.io/jq/
usdtomxn() {
fix=$(curl -s -X POST http://www.banxico.org.mx/pubDGOBC_Sisfix-war/Sisfix_JSON | jq .tcfix | sed -E -e 's/^.//g' -e 's/.$//g')
if [[ $1 ]]; then
echo "$1 * $fix" | bc
else
echo $fix
fi
}
mxntousd() {
fix=$(curl -s -X POST http://www.banxico.org.mx/pubDGOBC_Sisfix-war/Sisfix_JSON | jq .tcfix | sed -E -e 's/^.//g' -e 's/.$//g')
if [[ $1 ]]; then
echo "$1 / $fix" | bc
else
echo $fix
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment