我的bash脚本:
#!/bin/bash
scl enable devtoolset-9 bash
gcc --version结果:现在系统上启用了devtoolset-9,但是我没有gcc --version输出。gcc 9.x.x安装。在我输入scl enable devtoolset-9 bash时,系统运行devtoolset-9,我可以通过输入gcc --version来验证gcc版本。
如何运行bash脚本并获得gcc --version output?
发布于 2021-11-30 15:39:21
scl enable ...命令创建了一个新的shell;如果您一直在测试它,那么您可能已经得到了几个嵌套的shell层。如果您使用exit,您可能会看到来自基本系统的gcc --version输出。看看您对类似于pstree -s $$的东西有多深嵌套。
要使用scl运行gcc --version,只需将命令放在scl行上:
scl enable devtoolset-9 'gcc --version'参考资料:红色工具集9用户指南。
发布于 2023-05-31 08:22:29
要使脚本按您的意愿运行,需要使用scl命令来修改当前的bash会话,而不是生成新的会话。
你可以这样做
#!/usr/bin/env bash
# switch to GCC9 environment for the duration of the script
source scl_source enable devtoolset-9
gcc --versionhttps://unix.stackexchange.com/questions/679652
复制相似问题