Two-line prompt using Korn


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Two-line prompt using Korn
# 1  
Old 10-23-2013
Two-line prompt using Korn

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

The hosts that in use are either running RHEL kernel 2.6.8-xx with ksh88 or 2.6.9-xx with ksh93
This works perfectly for most hosts and I get the desired output:

Code:
userx@hosty:~
$ 
userx@hosty:~
$ cd Documents/
userx@hosty:~/Documents
$

But on some hosts I get this error when I login:

Code:
-ksh: syntax error: `;' unexpected
$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" 1074 "$PWD" ]] then; pr
int -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")

I also noticed that != changes to a number (1074 in this example) and increases by 1 if I hit Enter.

I'm using the same syntax on all hosts and cannot figure out this error.
My guess is the difference in the ksh version.

Please help me figure out what I'm doing wrong.
Also, is there a way to force ksh to behave consistently across older versions?
# 2  
Old 10-23-2013
Get the version of ksh you are usingecho $KSH_VERSIONand change all print statements to echo and see if that'd help...
This User Gave Thanks to shamrock For This Post:
# 3  
Old 10-23-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

The hosts that in use are either running RHEL kernel 2.6.8-xx with ksh88 or 2.6.9-xx with ksh93
This works perfectly for most hosts and I get the desired output:

Code:
userx@hosty:~
$ 
userx@hosty:~
$ cd Documents/
userx@hosty:~/Documents
$

But on some hosts I get this error when I login:

Code:
-ksh: syntax error: `;' unexpected
$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" 1074 "$PWD" ]] then; pr
int -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ")

I also noticed that != changes to a number (1074 in this example) and increases by 1 if I hit Enter.

I'm using the same syntax on all hosts and cannot figure out this error.
My guess is the difference in the ksh version.

Please help me figure out what I'm doing wrong.
Also, is there a way to force ksh to behave consistently across older versions?
Did you also notice the line break in the middle of print shown in red above?

Are you sure that .kshrc has the same contents on both systems?
# 4  
Old 10-23-2013
Quote:
Get the version of ksh you are using echo $KSH_VERSION and change all print statements to echo and see if that'd help...
echo $KSH_VERSION throws a blank line,
I use the vi mode, so an ESC and a CTRL +V gives me the version.
For simplicity, I'll narrow it down to the 93 versions and skip the 88 as host with the older versions are miminal.

I have a feeling its not the KSH version thats causing this.

The prompt works perfectly on:
Code:
Version AJM 93t+ 2010-02-02

It fails on
Code:
Version M 1993-12-28

Works well on some fails on others with:
Code:
Version AJM 93t+ 2010-06-21

On the hosts on which it failed, replacing print with echo ignores the newline character, throwing this output:
Code:
userx@hosty:~\n$



Quote:
Did you also notice the line break in the middle of print shown in red above?

Are you sure that .kshrc has the same contents on both systems?
I'm sorry that line break is actually the STDOUT on the terminal. I should have corrected it before pasting it here.
The .kshrc has no line breaks and is consistent on all hosts.
# 5  
Old 10-23-2013
Quote:
Originally Posted by capnpepper
On the hosts on which it failed, replacing print with echo ignores the newline character, throwing this output:
Code:
userx@hosty:~\n$


Well that's pretty close to what you want, why not now replace:
Code:
echo "\n$ "

with
Code:
echo;echo "$ "

# 6  
Old 10-23-2013
No luck

Code:
ksh93: syntax error: `end of file' unexpected
$(echo -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" 669= "$PWD" ]] then; echo -n "~${PWD#$HOME}"; else; echo -n "$PWD";fi;echo;echo "$ "

# 7  
Old 10-23-2013
Missing the close bracket

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

This User Gave Thanks to Chubler_XL 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