Created
October 6, 2012 13:31
-
-
Save snaga/3844951 to your computer and use it in GitHub Desktop.
Switch postgresql version for all the commands with using alternatives.
This file contains 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/sh | |
# alternatives-pgsql | |
# | |
# Switch postgresql version for all the commands with using alternatives. | |
# | |
# Copyright(C) 2012 Uptime Technologies, LLC. All rights reserved. | |
PATH=/usr/sbin:$PATH | |
export PATH | |
NUM=$1 | |
if [ -z $NUM ]; then | |
echo "id must be specified. abort." | |
echo "Usage; $0 <num>" | |
echo "" | alternatives --config pgsql-psql | grep bin/psql | |
echo | |
exit; | |
fi; | |
find /etc/alternatives/pgsql-* | \ | |
perl -e 's,.*/,,' -p | \ | |
awk '{ print "echo '$NUM' | alternatives --config " $1 }' | \ | |
sh | |
echo "" | alternatives --config pgsql-psql |
In case someone finds this on google again there was a slight typo in the command.
find /etc/alternatives/ -name 'pgsql-*' -exec basename {} \; | xargs -L 1 alternatives --auto
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just adding for anyone else that finds this post, can also use a one-liner in the form of:
find /etc/alternatives/ -name 'pgsql-' -exec basename {} ; | xargs -L 1 alternatives --auto