Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to find the command that would return me evaluated value of $PS1 variable or just shell prompt with current path.

e.g.

foo-user@bar-pc:~\bar

I would like to avoid using something like, since pwd will not truncate home_dir as ~.

echo "`whoami`@`hostname`:`pwd`"
share|improve this question
    
why is this bad question? to who ever hated. –  Dolphin Oct 15 '12 at 14:45
    
A hack that I am too lazy to complete: run a real shell and find someway to make it believe the input is a tty. –  billc.cn Oct 15 '12 at 20:19
    
Have a look here: stackoverflow.com/questions/10060500/… –  ed. Oct 15 '12 at 22:44
add comment

1 Answer 1

This is an implementation of billc.cn‘s suggestion:

        $(export PS1; echo exit | sh -i 2>&1)

Of course, if you have ! in PS1, it will be evaluated as “1” — unless you have some sort of history saving going on.  User name, hostname, current directory, date & time, etc., should be OK.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.