Skip to content

Instantly share code, notes, and snippets.

@smartree
Forked from snaga/alternatives-pgsql
Created July 8, 2021 15:57
Show Gist options
  • Save smartree/d73cef5bf9132199e05e6ea288a5dfa7 to your computer and use it in GitHub Desktop.
Save smartree/d73cef5bf9132199e05e6ea288a5dfa7 to your computer and use it in GitHub Desktop.
Switch postgresql version for all the commands with using alternatives.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment