Skip to content

Instantly share code, notes, and snippets.

@sukrosono
Created July 11, 2021 13:45
Show Gist options
  • Save sukrosono/b2b891b0a32aac554c8632ae594d079b to your computer and use it in GitHub Desktop.
Save sukrosono/b2b891b0a32aac554c8632ae594d079b to your computer and use it in GitHub Desktop.
#!/bin/sh
[ "$#" -lt "1" ] && {
echo "Configure current shell to use a specific major PHP version.
Usage: usephp 7"
exit 0
}
binary="php${1}"
wanted="/usr/bin/${binary}"
[ ! -f "${wanted}" ] && {
echo "'${binary}' not found. Using 'php'."
wanted="/usr/bin/php"
}
ln -sf "${wanted}" "${HOME}/bin/php"
inUse=$(php -nr "echo phpversion();")
echo "Shell configured to use PHP ${inUse}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment