linux - Bash 脚本 tee 命令语法问题

标签 linux bash shell ubuntu

我想在 ~/.profile 末尾回显以下行使用 tee 命令的文件:
export PATH="$HOME/.local/bin:$PATH"
为此,我的 bash 脚本如下所示

#!/bin/bash
path_env="export PATH="$HOME/.local/bin:$PATH""
echo $path_env| sudo tee -a  $HOME/.profile > /dev/null

但每当我执行脚本时,它也会执行 $PATH 和 $HOME 值并将其插入 ~./profile我不想要的文件。我只希望 bash 脚本传递确切的行,而不是用自己的值替换 $PATH 和 $HOME。

最佳答案

I only want the exact line to be passed by the bash script instead of replacing $PATH and $HOME with its own values.



哦,对了,所以不要扩展它。报价。
path_env='export PATH="$HOME/.local/bin:$PATH"'
echo "$path_env" | sudo tee -a "$HOME/.profile" > /dev/null

关于linux - Bash 脚本 tee 命令语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61477461/

相关文章:

c - 如果事件的数量超过给 epoll_wait() 的 maxevents 参数,剩下的事件会发生什么?

Bash 命令中的变量扩展

linux - 脚本中的 bash for 循环不会作为非根 cron 脚本运行

bash - 显示命令而不执行它们

bash - 生成新进程并返回到 Expect 脚本

linux - 在 Linux 中的特定行向文件添加文本

java - 暂停 JVM,仅修复 "jstack -F pid"

linux - Nasm - 符号 `printf' 导致 R_X86_64_PC32 重定位溢出

c - 使用 exec() 系列运行 "cd"命令

linux - 如何grep具有不同字母的文件?