Mac下如何忽略环境变量?

发布于 2024-10-19 02:42:38 字数 169 浏览 1 评论 0原文

希望有人能帮助我。我为 python 和其他一些库编写了一个安装 shell 脚本。所有软件包都安装在选定的文件夹中。例如“~/Desktop/inst”而不是“/usr/local”下。问题是,如果设置了一些环境变量,那么它们可能会搞乱安装。有可能以某种方式阻止这种情况发生吗?也许忽略设置的环境变量。或者还有其他技巧吗?

hope someone can help me. I wrote an installation shell script for python and some other libraries. All the packages are installed in a selected folder. For example "~/Desktop/inst" and not under "/usr/local". The problem, if there are some environment variables set, then they could mess up the installation. Is it somehow possible to prevent that? Maybe to ignore the set environment variables. Or is there maybe an other trick?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘寄 2024-10-26 02:42:38

是的...查找loginhook并通过使其成为您的mac的loginhook来运行您的脚本...这样当您的系统登录并且不存在变量时,您的应用程序应该运行良好,因为没有变量。希望有帮助。这是了解如何将应用程序设置为登录挂钩的链接[此处]。希望这有帮助
http://hints.macworld.com/article.php?story=2006081701162739

yeah...look up for loginhook and run your script by making it the loginhook for your mac...that way when ur system logs in and no variables exist, your application should run fine as there are no variables. hope it helps. here is a link for knowing how to set an app as loginhook [here]. hope this helps
http://hints.macworld.com/article.php?story=2006081701162739

盗梦空间 2024-10-26 02:42:38

您可以使用 printenv 来查看设置了哪些变量并取消设置它们(除了您想要/需要保留的变量,例如 PATH):

for var in $(printenv | sed 's/=.*//'); do
    case "$var" in
      TERM|SHELL|TMPDIR|USER|PATH|PWD|HISTCONTROL|SHLVL|HOME|LOGNAME|DISPLAY )
        : ;; # Leave these untouched
      * )
        unset "$var" ;;
    esac
done
PATH=/usr/bin:/bin:/usr/sbin:/sbin # Override existing PATH with standard value

You could use printenv to see what variables are set and unset them (except for the ones you want/need to keep, like PATH):

for var in $(printenv | sed 's/=.*//'); do
    case "$var" in
      TERM|SHELL|TMPDIR|USER|PATH|PWD|HISTCONTROL|SHLVL|HOME|LOGNAME|DISPLAY )
        : ;; # Leave these untouched
      * )
        unset "$var" ;;
    esac
done
PATH=/usr/bin:/bin:/usr/sbin:/sbin # Override existing PATH with standard value
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文