realpath in PS1 bash

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

realpath in PS1 bash

Peter Kuma-2
Hi folks

I didn't receive any response on debian-user, hopefully this is an
appropriate place to ask.

I'm wondering if it would be a good idea to have PS1 set to

'${debian_chroot:+($debian_chroot)}\u@\h:$(realpath "$(pwd)")\$ '

instead of the default

'${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

and make it a suggestion in /etc/skel/.bashrc for those users who want
to see the actual current working directory.

 From a security standpoint you could enter e.g.
/home/someoneelse/somedir/ and see me@debian:/home/someoneelse/somedir/$
in the prompt, but really be in /etc/ if somedir is a (potentially
malicious) symlink to /etc created by a different user. It could get
quite disastrous if you decide to run something like rm -r * in such a
directory.

It won't be very helpful with more sophisticated symlink race
conditions, but it is better than nothing.

Perhaps I should post it to bash package wishlist, what do you think?

Peter Kuma



--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: realpath in PS1 bash

Bernd Eckenfels
In article <[hidden email]> you wrote:
> I'm wondering if it would be a good idea to have PS1 set to
>
> '${debian_chroot:+($debian_chroot)}\u@\h:$(realpath "$(pwd)")\$ '

Personally I dont like having the shell spawn a executable. Since this will
slow down administration on heavyly loaded systems. Maybe "\pwd -P" as a
shell builtin acts a bit nicer. However I am not sure if it results in the
same path in all cases. And it is still traversing lots of inodes.

Gruss
Bernd


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: realpath in PS1 bash

Florian Weimer
* Bernd Eckenfels:

> And it is still traversing lots of inodes.

It's pretty much likely that those paths are in the dcache anyway, so
there's no need to fall back on inodes.


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]