From: Scott Bass on
<RANT>
Man, I miss my bash shell :-( I now have to use ksh88 on HP-UX. A !@#
$ 22 year old shell. But I digress...
</RANT>

First, details of my system:

> uname -a
HP-UX machinename B.11.23 U ia64 1493421762 unlimited-user license

> Cntl-V from the ksh shell:
Version 11/16/88

I've defined this test function:

function cd
{
command cd $@
echo IT WORKED
}

But the cd shell builtin takes precedence over the function.

Ok, not a biggie, I'll just name the function mycd and alias it to cd:

function mycd
{
command cd $@
echo IT WORKED
}

alias -x cd="mycd"

Two problems:

1) It doesn't change directories:

> cd /
IT WORKED
/net-users/sbass > (so it called the function but I'm still in my
home directory)

2) If I don't pass in parameters (say I want to cd to my home
directory), I get an error

> cd
mycd[2]: @: parameter not set
/net-users/sbass >

Is there an easy way to get around this issue, say with typeset?

Any help appreciated....

Thanks,
Scott

P.S.: My "real" function is using escape codes to set the prompt and
window title using PuTTY under Windoze as the client. This worked...

FG_BLACK="\033[30m"
FG_RED="\033[31m"
FG_GREEN='\033[32m'
FG_YELLOW='\033[33m'
FG_BLUE="\033[34m"
FG_PURPLE="\033[35m"
FG_CYAN='\033[36m'
FG_GRAY="\033[37m"
FG_CYAN='\033[36m'
FG_GRAY="\033[37m"

BG_BLACK="\033[40m"
BG_RED="\033[41m"
BG_GREEN="\033[42m"
BG_YELLOW="\033[43m"
BG_BLUE="\033[44m"
BG_PURPLE="\033[45m"
BG_CYAN="\033[46m"
BG_WHITE="\033[47m"

NC="\033[0m"

# prompt
PROMPT=$(echo "$FG_CYAN$(logname)@$(hostname)$NC:$FG_GREEN\${PWD}$NC >
")
WINDOW_TITLE=$(echo "\033]0;\${PWD}\007")

PS1=$PROMPT$WINDOW_TITLE

....until I wanted to change the window title to $(basename $PWD).

I couldn't find a way to delay the execution of $(basename $PWD) in
the prompt - it only set the title on first use. Which was when I
switched approach to using a function + aliasing the cd command.

From: Ed Morton on
On 2/10/2010 12:42 AM, Scott Bass wrote:
> <RANT>
> Man, I miss my bash shell :-( I now have to use ksh88 on HP-UX. A !@#
> $ 22 year old shell. But I digress...
> </RANT>
>
> First, details of my system:
>
>> uname -a
> HP-UX machinename B.11.23 U ia64 1493421762 unlimited-user license
>
>> Cntl-V from the ksh shell:
> Version 11/16/88
>
> I've defined this test function:
>
> function cd
> {
> command cd $@
> echo IT WORKED
> }
>
> But the cd shell builtin takes precedence over the function.
>
> Ok, not a biggie, I'll just name the function mycd and alias it to cd:
>
> function mycd
> {
> command cd $@
> echo IT WORKED
> }
>
> alias -x cd="mycd"
>
> Two problems:
>
> 1) It doesn't change directories:
>
>> cd /
> IT WORKED
> /net-users/sbass> (so it called the function but I'm still in my
> home directory)
>
> 2) If I don't pass in parameters (say I want to cd to my home
> directory), I get an error
>
>> cd
> mycd[2]: @: parameter not set
> /net-users/sbass>
>
> Is there an easy way to get around this issue, say with typeset?
>
> Any help appreciated....
>
> Thanks,
> Scott
>
> P.S.: My "real" function is using escape codes to set the prompt and
> window title using PuTTY under Windoze as the client. This worked...
>
> FG_BLACK="\033[30m"
> FG_RED="\033[31m"
> FG_GREEN='\033[32m'
> FG_YELLOW='\033[33m'
> FG_BLUE="\033[34m"
> FG_PURPLE="\033[35m"
> FG_CYAN='\033[36m'
> FG_GRAY="\033[37m"
> FG_CYAN='\033[36m'
> FG_GRAY="\033[37m"
>
> BG_BLACK="\033[40m"
> BG_RED="\033[41m"
> BG_GREEN="\033[42m"
> BG_YELLOW="\033[43m"
> BG_BLUE="\033[44m"
> BG_PURPLE="\033[45m"
> BG_CYAN="\033[46m"
> BG_WHITE="\033[47m"
>
> NC="\033[0m"
>
> # prompt
> PROMPT=$(echo "$FG_CYAN$(logname)@$(hostname)$NC:$FG_GREEN\${PWD}$NC>
> ")
> WINDOW_TITLE=$(echo "\033]0;\${PWD}\007")
>
> PS1=$PROMPT$WINDOW_TITLE
>
> ...until I wanted to change the window title to $(basename $PWD).
>
> I couldn't find a way to delay the execution of $(basename $PWD) in
> the prompt - it only set the title on first use. Which was when I
> switched approach to using a function + aliasing the cd command.
>

Below is my 20-year-old cd alias for ksh88. The $hbri, etc. are escape codes.

Ed.

if echo "$-"|grep i && test "`alias cd 2>/dev/null`" != "cd=cdprompt"
then
function cdprompt
{
\cd ${1:-$HOME}
echo " $hbri$PWD$nrm"
PS1="$hbri$UNAME $inv`basename $PWD`>$nrm "
}
alias cd=cdprompt
fi

From: Sven Mascheck on
Scott Bass wrote:

> <RANT>
> I now have to use ksh88 on HP-UX. A !@#$ 22 year old shell.

Only the first release ;-)

> HP-UX machinename B.11.23
>
>> Cntl-V from the ksh shell:
> Version 11/16/88

Early ksh is not verbose enough here. The HP-UX "ksh" is a ksh88c.
Instead, why not use "sh" (/bin, /sbin, etc.), a ksh88f?

> command cd $@

BTW: even older ksh don't know "command" yet,
"\cd" is an alternative to avoid functions.

> function mycd

sidenote: the notation "function" (compared to "cd() {..")
can (imho) only have disadvantages.

> command cd $@

You need "$@" for robustness.

> mycd[2]: @: parameter not set

This looks like you have a "set -u" somewhere.
--
http://www.in-ulm.de/~mascheck/various/shells/#hpux11
From: Scott Bass on
Hi Ed and Sven,

Thanks heaps for your replies. Much appreciated. I've got it working
now. Here is my final code:

mycd()
{
# Change directory
\cd "${@:-$HOME}"

# full path (but gets truncated in Windows icon if path is long)
# WINDOW_TITLE="\033]0;$PWD\007"

# basename (last token in path)
WINDOW_TITLE="\033]0;$(basename $PWD)\007"

PROMPT="$FG_GRAY$BG_RED$(logname)@$(hostname):\${PWD}$NC > "

# Set Window Title
print -n "$WINDOW_TITLE"

# Set Prompt
PS1=$(print -n $PROMPT)
}

@Ed:

I unconditionally define the function and alias in my .kshrc. If you
strongly feel it should be conditionally executed, say for performance
when sourcing the .kshrc, please let me know. Given my network
bandwidth to my Unix box, the performance of the .kshrc will not be
the bottleneck ;-)

@Sven: Some additional comments below

On Feb 11, 8:49 am, Sven Mascheck <masch...(a)email.invalid> wrote:
> Scott Bass wrote:
> > <RANT>
> > I now have to use ksh88 on HP-UX.  A !@#$ 22 year old shell.
>
> Only the first release ;-)
>
> > HP-UX machinename B.11.23
>
> >> Cntl-V from the ksh shell:
> > Version 11/16/88
>
> Early ksh is not verbose enough here. The HP-UX "ksh" is a ksh88c.
> Instead, why not use "sh" (/bin, /sbin, etc.), a ksh88f?

It's a new job, I'm not the Unix sysadmin, it's a remote machine, I
don't know how long it's been in service. I don't think they do much
maintenance - I think the sysadmin is afraid to change anything. I
asked for an install of bash (I miss my TAB command and path
completion) and ksh93 (TAB path completion?) but that got knocked
back. My command shell is ksh and unlikely to change.

>
> >   command cd $@
>
> BTW: even older ksh don't know "command" yet,
> "\cd" is an alternative to avoid functions.

Thanks. In all my Googling before posting this never got a hit. And
there isn't much differentiation between ksh88 and ksh93 via Google,
so I think most of my "ksh" hits were for ksh93.

> > function mycd
>
> sidenote: the notation "function" (compared to "cd() {..")
> can (imho) only have disadvantages.
>
> >   command cd $@
>
> You need "$@" for robustness.

Noted, thanks, see final code.

>
> > mycd[2]: @: parameter not set
>
> This looks like you have a "set -u" somewhere.

Not sure about this, but Ed's code fixed this issue.

> --http://www.in-ulm.de/~mascheck/various/shells/#hpux11

Thanks, I'll check out your URL asap. I'm sure it has a lot of useful
info. I used HP-UX *many* years ago but most of my recent work has
been on Solaris.

Kind Regards,
Scott

From: Sven Mascheck on
Scott Bass wrote:

>> > Version 11/16/88
>>
>> Early ksh is not verbose enough here. The HP-UX "ksh" is a ksh88c.
>> Instead, why not use "sh" (/bin, /sbin, etc.), a ksh88f?
>
> [...] I think the sysadmin is afraid to change anything.

If you mean installing packages: /bin/sh is onboard and it's not a
Bourne shell, but a more recent ksh on HP-UX. If you mean even
changing your login shell is not an option: just "exec sh".

>> > mycd[2]: @: parameter not set
>>
>> This looks like you have a "set -u" somewhere.

If this becomes relevant elsewhere: confirm with "echo $-",
it would contain a "u". Revert with "set +u" if it's global.

> [pointer] I'm sure it has a lot of useful info.

Rather: just a naked list, what shells exactly are there.