Posted on 10-23-2023 09:56 PM
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.
Solved! Go to Solution.
Posted on 10-24-2023 05:50 AM
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
Posted on 10-24-2023 05:50 AM
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
Posted on 10-24-2023 07:16 AM
This solved the issue, thank you mm2270!