Created
March 3, 2025 17:40
-
-
Save tongyul/5321db1eff69b2a420b8336308b599c6 to your computer and use it in GitHub Desktop.
Script for launching a subshell with modified PATH and LD_LIBRARY_PATH
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/bash -e | |
ENVNAME='CMU 15-213' | |
START="$PWD" | |
cd "$(dirname "$0")" | |
BIN="$PWD/bin" | |
LIB="$PWD/lib" | |
mkdir -p "$BIN" "$LIB" | |
cd "$START" | |
_ensure_bin_ () { | |
local des="$BIN/$1" | |
local src="$2" | |
printf '#!/bin/bash -e\n%s "$@"\n' "$src" >"$des" && chmod u+x "$des" | |
} | |
_ensure_lib_ () { | |
local des="$LIB/$1" | |
local src="$2" | |
ln -sf "$src" "$des" | |
} | |
_we_roll_ () {( | |
export PATH="$BIN:$PATH" | |
export LD_LIBRARY_PATH="$LIB:$LD_LIBRARY_PATH" | |
export PS1="[$ENVNAME] "'\u@\h:\w> ' | |
exec "$SHELL" | |
)} | |
# GCC | |
_ensure_bin_ gcc /usr/bin/gcc-11 | |
# Clang/LLVM | |
_ensure_bin_ clang /usr/bin/clang-14.0.6 | |
_ensure_bin_ clang++ /usr/bin/clang++-14.0.6 | |
_ensure_bin_ llvm /usr/bin/llvm-14.0.6 | |
_ensure_bin_ opt /usr/bin/opt-14.0.6 | |
_ensure_lib_ libLLVM-14.so.1 /usr/lib64/libLLVM.so.14 | |
# ...And that's it!! | |
_we_roll_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment