Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Watchout for PS1 + set -o vi GOTCHA

Status
Not open for further replies.

d3vzero

Technical User
Aug 19, 2002
74
IE
Hi Guys,

Just got hit with this one, resulting in the automatic NULL'ing of a script, and thought I'd pass it on.

Have had my prompt set to the following for years with no problem till now.

export PS1="`whoami`@`hostname`:"'$PWD> '

I also use ksh Command history via set -o vi.

I was trying to recall the past execution command of a script I was working on. The command history was a little muddled (due to multiple sessions), so I Ctrl-c'd and tried to call it up again.

This time I got two prompts together and then the command.

Thinking that the <CR> had just not displayed for some reason I hit Return .... with the horrible result of null'ing the script I was working on.

I figure that the timing of my Ctrl-c must somehow have stuffed the PS1 cmd exec, resulting in my prompt being inserted as a command that can be interpreted by ksh.

This situation seems to need the following to cause an issue.

1. PS1 ending in >
2. Command History in use (set -o vi).
3. Use of Ctrl-c within Command History Selection.

Needless to say after loosing about 200 lines of complex code amendments, I have now changed my PS1 prompt to end in &quot;:&quot; :-(

Here's the screen dump of the situation.

user1@host1:/home/user1/projects/ops> ./ops_ctrl -dio
user1@host1:/home/user1/projects/ops> r
user1@host1:/home/user1/projects/ops> dio
user1@host1:/home/user1/projects/ops> ksh: dio: not found
user1@host1:/home/user1/projects/ops> user1@host1:/home/user1/projects/ops> ops_ctrl -r
ksh: user1@host1:/home/user1/projects/ops: not found
user1@host1:/home/user1/projects/ops>
user1@host1:/home/user1/projects/ops> ops_ctrl -r
user1@host1:/home/user1/projects/ops> echo $?
0
user1@host1:/home/user1/projects/ops> ops_ctrl -dr
user1@host1:/home/user1/projects/ops> ls -alt
total 16
-rwxr-x--- 1 user1 staff 0 29 Aug 13:05 ops_ctrl
drwxr-x--- 2 user1 staff 512 27 Aug 11:09 .
drwxr-x--- 6 user1 staff 512 22 Aug 14:08 ..
user1@host1:/home/user1/projects/ops> history
529 ./ops_ctrl -dio
530 dio
531 user1@host1:/home/user1/projects/ops> ops_ctrl -r
532 ops_ctrl -r
533 echo $?
534 ops_ctrl -dr
535 ls -alt
536 history

Dont get caught.

Best Regards to ALL, Peter.



 
I good reason to start using CVS......

--
| Mike Nixon
| Unix Admin
|
----------------------------
 
I did'nt loose the original (400+ lines) file .... just the changes (200+ lines) I had made over the course of the day.

Code Control will prevent the loss of your original file .... but sadly not the loss of your changes pre Code Control Checkin. :-(

Best Regards, Peter.

 
could be the fact the > is inside the ', that is odd. more likely you are just very practiced in CRTL-C. =) i used that same one and never saw that issue. coincidentally, i just changed my prompt last week:

export PS1=&quot;$(whoami)@$(hostname):\$PWD/[!]&quot;

i kept grabbing the > when mouse-selecting text. silly me. nice way to clear up some filespace, though.

IBM Certified -- AIX 4.3 Obfuscation
 
lol ....

Yeah .... I had'nt thought of the cut 'n paste angle ... deadly. ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top