marshmello
marshmello

Reputation: 101

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.

Upvotes: 0

Views: 232

Answers (1)

KamilCuk
KamilCuk

Reputation: 141523

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

Upvotes: 1

Related Questions