1
目前,我有一個加載我的環境變量的腳本。而我採購這樣的:如何使我的環境變量可用於sudo命令?
#!/bin/bash
set -x
# sourcing my env variables
. /etc/profile.d/company_env.sh > /dev/null 2>&1
clear_known_hosts(){
local known_hosts="${NAGIOS_HOME}/.ssh/known_hosts"
# clear
su - nagios -c "echo '' > ${known_hosts}"
}
但是,除去採購的部分,因爲我不想將其添加到可能產生,我sudo
命令無法找到我的環境變量每個腳本,例如NAGIOS_HOME
,這是空的。
有什麼建議嗎?
'sudo -E'或'sudo --preserve-env'? – anishsane
@anishsane將此添加爲答案。 – Sinkingpoint