th3*_*0id 46 linux command-line bash command scl
我安装了较新版本的 devtoolset (1.1),并想知道如何将这些永久设置为默认值。现在,当我通过 ssh 进入运行 CentOS 的服务器时,我必须运行此命令scl enable devtoolset-1.1 bash
我尝试将它添加到 ~/.bashrc 并简单地将其粘贴到最后一行,但没有成功。
Des*_*ica 83
在您的~/.bashrc或~/.bash_profileSimply 源中,使用devtoolset 提供的“启用”脚本。例如,使用 Devtoolset 2,命令是:
source /opt/rh/devtoolset-2/enable
Run Code Online (Sandbox Code Playgroud)
或者
source scl_source enable devtoolset-2
Run Code Online (Sandbox Code Playgroud)
效率更高:没有叉形炸弹,没有棘手的外壳
oHo*_*oHo 14
一个替代方案source /opt/rh/devtoolset-4/enable是
source scl_source enable devtoolset-4
Run Code Online (Sandbox Code Playgroud)
上面的 shell 脚本scl_source比使用硬编码路径更优雅(在另一台机器上可能会有所不同)。然而scl_source,因为/opt/rh/devtoolset-4/enable用途scl_source和其他东西而减少。
要使用scl_source您可能需要升级包scl-utils
yum update scl-utils # old scl-utils versions miss scl_source
Run Code Online (Sandbox Code Playgroud)
快速复制粘贴
echo 'source scl_source enable devtoolset-4' >> ~/.bashrc
# Do not forget to change the version ?
Run Code Online (Sandbox Code Playgroud)
好奇的人的源代码
scl_source源代码示例:https :
//gist.github.com/bkabrda/6435016
将scl_source在我的Red Hat 7.1安装
#!/bin/bash
_scl_source_help="Usage: source scl_source <action> [<collection> ...]
Don't use this script outside of SCL scriptlets!
Options:
-h, --help display this help and exit"
if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
echo "$_scl_source_help"
return 0
fi
if [ -z "$_recursion" ]; then
_recursion="false"
fi
if [ -z "$_scl_scriptlet_name" ]; then
# The only allowed action in the case of recursion is the same
# as was the original
_scl_scriptlet_name=$1
fi
shift 1
if [ -z "$_scl_dir" ]; then
# No need to re-define the directory twice
_scl_dir=/etc/scl/conf
if [ ! -e $_scl_dir ]; then
_scl_dir=/etc/scl/prefixes
fi
fi
for arg in "$@"; do
_scl_prefix_file=$_scl_dir/$arg
_scl_prefix=`cat $_scl_prefix_file 2> /dev/null`
if [ $? -ne 0 ]; then
echo "Can't read $_scl_prefix_file, $arg is probably not installed."
return 1
fi
# First check if the collection is already in the list
# of collections to be enabled
for scl in ${_scls[@]}; do
if [ $arg == $scl ]; then
continue 2
fi
done
# Now check if the collection isn't already enabled
/usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
_scls+=($arg)
_scl_prefixes+=($_scl_prefix)
fi;
done
if [ $_recursion == "false" ]; then
_i=0
_recursion="true"
while [ $_i -lt ${#_scls[@]} ]; do
_scl_scriptlet_path="${_scl_prefixes[$_i]}/${_scls[$_i]}/${_scl_scriptlet_name}"
source "$_scl_scriptlet_path"
if [ $? -ne 0 ]; then
echo "Can't source $_scl_scriptlet_name, skipping."
else
export X_SCLS="${_scls[$_i]} $X_SCLS"
fi;
_i=$(($_i+1))
done
_scls=()
_scl_prefixes=()
_scl_scriptlet_name=""
_recursion="false"
fi
Run Code Online (Sandbox Code Playgroud)
小智 5
问题是scl enable devtoolset-1.1 bash创建了一个新的 bash shell。所以当你把它放在你的 .bashrc 中时,它会创建一个新的 shell...它加载你的 .bashrc,它运行scl enable devtoolset-1.1 bash,它创建一个新的 shell,它加载你的 .bashrc... Forkbomb!
你可能想要在你的 .bashrc 中这样的东西:
if [ "$(gcc -dumpversion)" != "4.7.2" ]; then
scl enable devtoolset-1.1 bash
fi
Run Code Online (Sandbox Code Playgroud)
或者
if [ -z "$TRIEDSCLDEVTOOLSET" ]; then
export TRIEDSCLDEVTOOLSET=true
scl enable devtoolset-1.1 bash
fi
Run Code Online (Sandbox Code Playgroud)
exit两次。