Skip to content

Instantly share code, notes, and snippets.

@siddhpant
Created July 11, 2026 12:27
Show Gist options
  • Select an option

  • Save siddhpant/a25c0be9635b932f7442efa8e716a1cd to your computer and use it in GitHub Desktop.

Select an option

Save siddhpant/a25c0be9635b932f7442efa8e716a1cd to your computer and use it in GitHub Desktop.
Update alternative helper aliases
update-alternatives-install() {
read -p "Enter command name whose alternative is being set: " cmd_name
echo
read -p "Enter path of the link to '$cmd_name': " cmd_link
echo
read -p "Enter path to the actual executable which is being set as alternative: " alt_path
echo
read -p "Enter the priority of the alternative: " alt_priority
echo
echo
update_cmd_str="sudo update-alternatives --install $cmd_link $cmd_name $alt_path $alt_priority"
echo $update_cmd_str
echo
eval "$update_cmd_str"
}
add-gcc-alternatives() {
read -p "Enter gcc version number: " ver
echo
# Slave idea from: https://stackoverflow.com/a/44217770
# We should probably add other slaves too, like cross-compiler ones.
slaves=(g++ gcov gcov-dump gcov-tool gcc-ar gcc-nm gcc-ranlib)
NL=$'\n'
TAB=$'\t'
update_cmd_str="sudo update-alternatives"
update_cmd_str+=" \\${NL}${TAB}"
update_cmd_str+="--install /usr/bin/gcc gcc /usr/bin/gcc-${ver} ${ver}"
for slave in "${slaves[@]}"; do
update_cmd_str+=" \\${NL}${TAB}${TAB}"
update_cmd_str+="--slave /usr/bin/${slave} ${slave} /usr/bin/${slave}-${ver}"
done
echo "$update_cmd_str"
echo
eval "$update_cmd_str"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment