gpt4 book ai didi

linux - 如何将变量从不同用户的 shell 脚本导出到当前用户?

转载 作者:太空宇宙 更新时间:2023-11-04 11:47:13 25 4
gpt4 key购买 nike

我有两个用户 test1 和 test2 我有一些变量要从 test1 中的 sample.sh 导出。我想将 test1 sample.sh 中的值导出到我的 test2 中,这是我所在的当前用户:

# sample.sh
export test="test1"
echo "hi"
export test2="test2"

我试过这个命令:

su -test1 -c  ". /data/home/test1/.sample"

echo 正在我当前的用户 test2 中工作和打印。但是当我尝试 printenv 时,我看不到其中的任何测试或 test2。

最佳答案

这是因为 export 将变量导出到当前 session 中。显然,当您注销时它会消失。如果你想永久导出它,你应该修改一些配置文件,比如:

 /home/test2/.bashrc
/home/test2/.bash_profile

所以你可以将这些变量附加到这个文件中。 (cat my_env >>>/home/test2/.bashrc)

关于linux - 如何将变量从不同用户的 shell 脚本导出到当前用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57253947/

25 4 0
文章推荐: java - keystore 异常 : This keystore does not support probing and must be loaded with a specified type
文章推荐: css - 如何将背景图像放在
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com