[TriLUG] Changing slashes to backslashes in prompt
Bick via TriLUG
trilug at trilug.org
Fri Apr 19 15:55:37 EDT 2019
I am reading through a Linux book right now and one of the exercises in the chapter about environment variables is to make the prompt look more Windows like. Specifically, I am supposed to make the prompt display C:\directory. I first attempted to use sed to accomplish it like this: PS1='C:$(echo $(pwd) | sed 's:/:\\:g') '. The result is C:parentDirchildDir. It does not print slashes. If I just put the command I am calling directly into the bash prompt, I get the proper output: C:\parentDir\childDir.
I thought maybe the problem was that the single slash was being reinterpreted as an escape character when PS1 was being read, so I tried using four slashes (so that two would be present in the PS1 string). Again typing this at the command prompt worked (output was C:\\parentDir\\childDir), but it didn't work as part of assigning it to PS1.
I have also tried assigning the commands I want to run to a variable, $NEWPWD, I created in PROMPT_COMMAND. I then used the variable in the PS1 assignment. This didn't work either.
I have successfully replaced the slashes with letters, numbers, and even an exclamation point (which needed to be escaped by a backslash) using ALL of the above methods. Any ideas why this doesn't work with backslashes?
Thanks,
Chris
More information about the TriLUG
mailing list