1836375 Members
2342 Online
110100 Solutions
New Discussion

Re: time on PS1

 
roberto salvatori
Frequent Advisor

time on PS1

how can i put a system time on PS1 on .profile?
thank for your support
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: time on PS1

export PS1="`hostname`(!)`date`# "



Pete

Pete
Donny Jekels
Respected Contributor

Re: time on PS1

set_prompt() {
#
# put this function in your .profile
# and rock
TIME=$(date +%H:%M)
export PS1=":`hostname`:`/usr/bin/whoami`:\${PWD}:\${TIME} "
}

then make sure to call the function towrds the end of your .profile

set_prompt



live free or die
donny
"Vision, is the art of seeing the invisible"
Dario_1
Trusted Contributor

Re: time on PS1

Hi!

Try this for full date including the time:

export PS1="`date -u +%c`# "

This will only give you the date:
export PS1="`date`# "

Regards,

DR
Donny Jekels
Respected Contributor

Re: time on PS1

another note on time in your prompt.

sad but true. it does not keep up with the system time.

you will only notice the logged in time
if you find simething that can do it let me know.

tip: never use ">" in your prompt to end it.

reason: say your prompt is like this

myhp:myuser:/home/myuser:13:20 >

then for some reason down the line you want to cut and paste from your console.

guess what will happen if you accidently cut and paste this

> /etc/passwd

or any othe file which you have write privileges to

peace,
live free or die
donny




"Vision, is the art of seeing the invisible"
Pete Randall
Outstanding Contributor

Re: time on PS1

As previously stated, the date command (with whatever formatting you want to just get time or whatever) will give you the time that you pressed the enter key and got the prompt. It will not refresh itself like a running clock, if that's what you mean.


Pete

Pete
roberto salvatori
Frequent Advisor

Re: time on PS1

thanks to all but it's not what i want. i want that the time, after every command, refreshing itself, like on linux. i don't know if is possible on hp-ux but ... everithing is possible.
waiting for you, best regards
roberto salvatori
Frequent Advisor

Re: time on PS1

thank u all
Donny Jekels
Respected Contributor

Re: time on PS1

are you using bash on linux?

that is a built in feature of bash.

compile and install bash on hp-ux. then you'll be set.

also, points would be nice
"Vision, is the art of seeing the invisible"
roberto salvatori
Frequent Advisor

Re: time on PS1

i'm using a sh shell like root and i don't want to change anything on system (hp-ux 11).
points u'll have. don't worry about it.
best regards