简体   繁体   English

Bash 脚本 tee 命令语法问题

[英]Bash script tee command syntax issue

I want to echo the following line at the end of ~/.profile file using tee command:我想使用 tee 命令在~/.profile文件的末尾回显以下行:

export PATH="$HOME/.local/bin:$PATH"

To do this my bash script looks like this为此,我的 bash 脚本如下所示

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

But whenever I am executing the script it is also executing $PATH and $HOME value and inserts that in ~./profile file which I do not want.但是,每当我执行脚本时,它也会执行 $PATH 和 $HOME 值并将其插入到我不想要的~./profile文件中。 I only want the exact line to be passed by the bash script instead of replacing $PATH and $HOME with its own values.我只希望 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.我只希望 bash 脚本传递确切的行,而不是用自己的值替换 $PATH 和 $HOME。

Och, right, so do not expand it.哦,对了,所以不要扩展它。 Quoting.报价。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM