Two-line prompt using Korn


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Two-line prompt using Korn
# 8  
Old 10-24-2013
Same error as before...

Code:
-ksh: line 1: syntax error: `;' unexpected
$(echo -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" 1002 "$PWD" ]] then; echo -n "~${PWD#$HOME}"; else; echo -n "$PWD";fi;echo;echo "$ ")

But this now ONLY fails on hosts with Version M 1993-12-28

It works on the hosts with Version AJM 93t+ 2010-06-21.
# 9  
Old 10-24-2013
Quote:
Originally Posted by capnpepper
Same error as before...

Code:
-ksh: line 1: syntax error: `;' unexpected
$(echo -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" 1002 "$PWD" ]] then; echo -n "~${PWD#$HOME}"; else; echo -n "$PWD";fi;echo;echo "$ ")

But this now ONLY fails on hosts with Version M 1993-12-28

It works on the hosts with Version AJM 93t+ 2010-06-21.
Try the following:
Code:
PS1='$(printf "%s@%s:" "$(logname)" "$(hostname)";[ "${PWD#$HOME}" == "$PWD" ] || printf "~";printf "%s\n$ " "${PWD#$HOME}")'

Note that I reversed some of the logic so I could use "==" instead of "!=". I use set -o vi, but I have heard of some cases where set -o emacs sometimes invokes the command history mechanism when != is used. If that is part of your problem (i.e. the 1002 in red above), this change should avoid it. I used printf instead of echo -n because it is more portable. (Using echo -n abc in ksh on a Solaris system (and some other UNIX branded systems) should print -n abc followed by a newline rather than abc without a newline that you would get with ksh on some other systems.
This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 10-24-2013
Beautiful! Thank you... that worked perfectly on every host that failed earlier.
And thanks again for the useful tips. Much appreciated!
# 11  
Old 10-24-2013
Quote:
Originally Posted by capnpepper
I'm attempting to set up a two-line prompt using Korn.

This is what I've set up in .kshrc

Code:
PS1='$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]]? then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")'

And in .profile,
Code:
ENV="$HOME/.kshrc"; export ENV

After closer inspection your command line does have unwanted/missing semicolons (shown in red above) so try the one below...
Code:
PS1=$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]]; then print -n "~${PWD#$HOME}"; else print -n "$PWD";fi;print "\n$ ")

which should work on all ksh versions...
This User Gave Thanks to shamrock For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

RFC - Korn shell prompt

Hi, I am learning shell scripting for the first time. I use AT&T Korn Shell, Version AJM 93u+ 2012-08-01, compiled from source on NetBSD. So far I have managed to set up what I think is a useful and pleasing shell prompt, which can be seen in the image attached to this post. The prompt is... (2 Replies)
Discussion started by: gezley
2 Replies

2. Shell Programming and Scripting

Korn Shell script to insert at specific line

Hi, I am trying to put together a Korn Shell script to insert at a specific line. The system we use is SunOS 5.10 I can get the line number by using:- num=`sed -n '/export ENV/=' ./tmp.file` Not getting much headway using the above variable's value to insert - export SYBASE=/opt/sybase15... (5 Replies)
Discussion started by: aj8200
5 Replies

3. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

4. Shell Programming and Scripting

MKS KORN SHELL WONT EXECUTE from windows command prompt

Can anybody help me with this small script , the script works fine and launches the IE from c:\documents and settings \test\my documents>ksh prompt $RunURL1.sh this scitpt works and launches the ie from ksh , but when i schedule it to run the script then i get the error box saying command:1... (2 Replies)
Discussion started by: venu
2 Replies

5. Shell Programming and Scripting

Database connection from korn shell prompt

Hello, I want to connect to Database through shell command line. Here is my command from putty, $ sqlplus -S ora/ora@ORA But I am not able to connact to database. If this command succed, what is the expected output on shell prompt? Could you please let me know how to connact to... (3 Replies)
Discussion started by: Poonamol
3 Replies

6. Shell Programming and Scripting

delete new line character ( - ) , korn shell

Hi guys , i need help so bad on this issue.. Basically i have to delete the line continuation symbol of first column variable and add the truncated part of that word in next line to first line. here i written sample 3 lines but originally i have bunch of lines in that file. client1_day- ... (3 Replies)
Discussion started by: chrismorgan
3 Replies

7. AIX

korn prompt autocompletion possible ?

My client`s system is an AIX 4.2 and using the Kron shell. I was just wondering if it is possible to have the prompt autocompletion enabled on it without changing shell version. By autocompletion, I mean to automatically complete the filenames or directories we type in using the Tab key. (2 Replies)
Discussion started by: Browser_ice
2 Replies

8. AIX

prompt line

Hlo sir My system file / system file is full and i am unable to enter any command such as ls or to start my server RS6000 The network is blocked and the users are log off. (0 Replies)
Discussion started by: sobnc
0 Replies

9. UNIX for Dummies Questions & Answers

Path in prompt line?

Can anyone tell me what makes the current path appear in the prompt ? thx (4 Replies)
Discussion started by: Leitwolf
4 Replies

10. UNIX for Dummies Questions & Answers

2 line prompt

I know this is very easy. I just am having a problem determining how to do it. I want to have a 2-line command prompt when you hit return. I have no problem creating or exporting a PS1, but can't make into 2 lines. hostname-user:/path/to/dir # I really should know this, but my brain... (7 Replies)
Discussion started by: Kelam_Magnus
7 Replies
Login or Register to Ask a Question