如何快速修改Shell环境变量? [英] How do I modify a shell environment variable in swift?
本文介绍了如何快速修改Shell环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Process
时如何访问其中一个shell env var?如果我使用environment
进行设置,它将更改所有的环境变量.
How can I access one of the shell env vars when using Process
? If I use environment
to set them, it will change all of the env vars.
let task = Process()
// How do I modify PATH only instead of setting the whole dictionary
task.environment = ["PATH": "/usr/local/bin"]
推荐答案
您可能会解决此问题,并将其添加到ProcessInfo.processInfo.environment
(继承的环境)您的自定义路径(或所需的任何路径)上:
You might solve it appending on ProcessInfo.processInfo.environment
(the inherited environment) your custom path (or whatever you need):
let task = Process()
var environment = ProcessInfo.processInfo.environment
environment["PATH"] = "/usr/local/bin"
task.environment = environment
print(task.environment ?? "")
这篇关于如何快速修改Shell环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文