【发布时间】:2021-08-17 20:19:50
【问题描述】:
我正在尝试编写一个名为 updateFile.sh 的 bash 脚本。目前如下:
function insertIntoFile(){
local variable=$1
local target=$2
echo "${variable}" | tee -a "${target}";
}
insertIntoFile "export/ foo=bar" "~/.bash_profile"
运行bash -x ./updateFile.sh
对于输出,我得到...
...
+ echo 'export/ foo=bar'
+ tee -a '~/.bash_profile'
export/ foo=bar
然而,当我cat ~/.bash_profile
给定的字符串仍然是空的。
我试过不带斜线的导出,所以我知道不是这样,我已经挖掘了堆栈溢出,我所看到的一切似乎都表明这应该可以工作,但我不明白为什么它不是或如何解决它。
【问题讨论】:
标签: bash