简体   繁体   中英

Bash script tee command syntax issue

I want to echo the following line at the end of ~/.profile file using tee command:

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

To do this my bash script looks like this

#!/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. I only want the exact line to be passed by the bash script instead of replacing $PATH and $HOME with its own values.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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