Skip to main content
Solved

Write Exact Text to File


Forum|alt.badge.img+5
  • New Contributor
  • 8 replies

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. 

 

Best answer by mm2270

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 original
Did this topic help you find an answer to your question?

2 replies

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • October 24, 2023

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

Forum|alt.badge.img+5
  • Author
  • New Contributor
  • 8 replies
  • October 24, 2023
mm2270 wrote:

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

This solved the issue, thank you mm2270!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings