[TriLUG] Changing slashes to backslashes in prompt

Mike Viscount via TriLUG trilug at trilug.org
Fri Apr 19 17:49:11 EDT 2019


I do agree with what everyone else has said ... this is a stupid exercise
because C:\parent_dir\child_dir is totally meaningless in *nix.  But that
doesn't mean we shouldn't help you learn something from it since there are
a couple good learning points in the exercise - it's the application of
them that is stupid!

I'll address a couple of the things you're trying, problems you're hitting,
and hopefully solutions that you can learn something from ....

Assuming you're running bash ....

I don't think there's an environment variable "pwd" but there is a command
(builtin) pwd:

mviscount at eruleadm:~> pwd
/home/mviscount

and you could get the output from that command into your echo statement by
using single back ticks ...

mviscount at eruleadm:~> echo `pwd`
/home/mviscount

but from your syntax I suspect you're looking for the environment variable
"PWD" .... note that it's upper case and that matters in *nix.

mviscount at eruleadm:~> echo $PWD
/home/mviscount

The (or at least one other thing) you're running into is that your sed
syntax is bad.  Since the "/" and "\" are special characters you need to
escape them by preceeding them with "\"  so for example to change the "/"
to a "\" you would need to do the following:

With pwd command ....

 mviscount at eruleadm:~> pwd | sed 's/\//\\/g'
\home\mviscount

or with PWD environment variable

mviscount at eruleadm:~> echo $PWD | sed 's/\//\\/g'
\home\mviscount

and if you want a C: (meaningless BTW) you could do

mviscount at eruleadm:~> echo C:`pwd` | sed 's/\//\\/g'
C:\home\mviscount

Now .... getting all this into your PS1 environment variable is another
task.  Keep in mind that it has to keep changing ... eg it can not be
static.  I've never used the PS1 command thing and since it's Friday night
and cold beer is in my fridge I'll leave that exercise to you.  But, I'd
also say you should learn the pwd vs. PWD, \ techniques to escape special
characters since that's not limited to sed, how to use the back tic to run
a command, and call it good since going back to point 1 - the output of
this excercise is meaningless in *nix.

Hope that makes some kind of sense .... if not come on over and I'll give
you a beer :-)

Mike





On Fri, Apr 19, 2019 at 5:00 PM Joseph Mack NA3T via TriLUG <
trilug at trilug.org> wrote:

> On Fri, 19 Apr 2019, Bick via TriLUG wrote:
>
> > 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'm sorry that someone is asking you to do this.
>
> It indicates to me that someone thinks Linux is a cheap way to get Windows
> functionality, rather than a well designed system that stands on its own.
>
> I hope you don't wind up in a job where someone wants you to do this.
>
> Joe
>
> --
> Joseph Mack NA3T EME(B,D), FM05lw North Carolina
> jmack (at) wm7d (dot) net - azimuthal equidistant
> map generator at http://www.wm7d.net/azproj.shtml
> Homepage http://www.austintek.com/ It's GNU/Linux!
> --
> This message was sent to: MikeV <mviscount at gmail.com>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : https://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web  :
> https://www.trilug.org/mailman/options/trilug/mviscount%40gmail.com
> Welcome to TriLUG: https://trilug.org/welcome


More information about the TriLUG mailing list