Write Exact Text to File

b_rant
New Contributor II

Hello, 

Question: How do you write the exact text to the file instead if it spelling out the $PATH ??

I am trying to copy a line with the echo command to a text file. The command works, however it writes the actual path instead of the text itself. 

Example: 

echo "export PATH=~/.npm-global/bin:$PATH" | cat >> /Users/$CURRENT_USER/.profile

Writes: export PATH=~/.npm-global/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/jamf/bin 

Instead of " export PATH=~/.npm-global/bin:$PATH " 

I am scratching my head on this and can't seem to find any answers online, running as the user does not seem to work either as Jamf still fills in the $PATH with it's own seen above. Running from terminal as user still fill's in the path instead of the exact text. 

 

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

You need to escape the $ in the $PATH variable so the shell won't do expansion.

echo "export PATH=~/.npm-global/bin:\$PATH" | cat >> /Users/$CURRENT_USER/.profile

View solution in original post

2 REPLIES 2

mm2270
Legendary Contributor III

You need to escape the $ in the $PATH variable so the shell won't do expansion.

echo "export PATH=~/.npm-global/bin:\$PATH" | cat >> /Users/$CURRENT_USER/.profile

b_rant
New Contributor II

This solved the issue, thank you mm2270!