ksh (88/93), setting of PATH in ~/.profile

ksh (88/93), setting of PATH in ~/.profile

Post by ssve.. » Fri, 30 Apr 2004 07:20:10



I've looked around for some weeks trying to find a way to solve my
problem.
I want to add paths (=values) to PATH and other environment variables.
I don't want the same value to be repeated in the EV. I want to be
able to add
one digit values (e.g. ".") as wll as longer strings.
"." may be translated to "::" (null value) as ":" is used as
delimiter.

My aproach is a simple function defined within the script or maybe
separate in its own file, placed in a directory pointed to by both
$PATH and $FPATH.
The old way didn't work with "." as argument.
The new way don't work at all. (bash:
PATH=$PATH:/export/home/ssvedin/bin: A file or directory in the path
name does not exist.)
Target environment is IBM running AIX 5.2, ksh as well as ksh93 is
available.

Analyzing the errors makes me think that bash is used as shell
allthough ksh is specified in the shabang. (Bash is my default login
shell, but this script should be run for other users who have ksh as
shell.) It also seems that bash, or whatever shell is executing,
treats the statement as a file to be launched???

old way:
postfixpath()
{
        if [ $( /bin/expr "$PATH" : ".*:*$1" ) -eq 0 ]
        then
                PATH=$PATH:/$1
        fi

Quote:}

a slightly modified way (two params with the second defaulting to
PATH):
# $1 - path, e.g. ~/bin
# $2 - EV, e.g. MANPATH, dflt=PATH
postfixpath()
{
    endix=$( /bin/expr "\$${2:-PATH}" : ".*:*$1" )
    echo "endix=$endix"
        if [ $endix -eq 0 ]
        then
            ${2:-PATH}=\$${2:-PATH}:$1                    #> /dev/null 2>&1
        fi

Quote:}

the new one:
taken from linux (Mandrake 9.2):
Sorry, don't have it available at this computer for the moment!

A call to add /usr/bin to PATH looks like:

    postfixpath /usr/bin

Any ideas would be appreciated!
Staffan Svedin

 
 
 

ksh (88/93), setting of PATH in ~/.profile

Post by Icarus Sparr » Sat, 01 May 2004 08:58:08



Quote:> I've looked around for some weeks trying to find a way to solve my
> problem.
> I want to add paths (=values) to PATH and other environment variables.
> I don't want the same value to be repeated in the EV. I want to be
> able to add
> one digit values (e.g. ".") as wll as longer strings.
> "." may be translated to "::" (null value) as ":" is used as
> delimiter.

> My aproach is a simple function defined within the script or maybe
> separate in its own file, placed in a directory pointed to by both
> $PATH and $FPATH.
> The old way didn't work with "." as argument.
> The new way don't work at all. (bash:
> PATH=$PATH:/export/home/ssvedin/bin: A file or directory in the path
> name does not exist.)
> Target environment is IBM running AIX 5.2, ksh as well as ksh93 is
> available.

It is rather more efficient to use the builtin pattern matching
available in the shells. Tested with on a debian linux system with
dash (0.2.45)
bash (2.05b-2-14)
ksh93 (Version M 1993-12-28 o+)
zsh-beta (4.2.0-dev-1+20040423-1)

postfixpath() {
        # Append a directory specified by the first parameter
        # to the environment variable specified by the second parameter
        # but only if it is not already present. The second parameter
        # defaults to PATH. Entries are seperated by : characters
        # Only compares by name, and does not protect against
        # /usr/bin/., /usr/./bin, /usr//bin, etc
        # Icarus Sparry - 29 Apr 2004
        target=${2:-PATH}
        case "$1" in
        "")   d="." ;;
        *:*)    echo "Can not add a directory with a : to $target" >&2
                return 1 ;;
        *)      d="$1" ;;
        esac
        if [ -d "$d" ] ; then
                e='case "$'$target'" in
                "$d"|"$d":*|*:"$d"|*:"$d":*) ;;
                "")   '$target'="$d" ;;
                *)      '$target'="$'$target':$d" ;;
                esac'
                eval "$e"
        fi

- Show quoted text -

Quote:}


 
 
 

ksh (88/93), setting of PATH in ~/.profile

Post by ssve.. » Sat, 01 May 2004 17:33:54


Thanks for the idea Icarus, I will try it out on the AIX ksh next week.
//Staffan


> > I've looked around for some weeks trying to find a way to solve my
> > problem.
> > I want to add paths (=values) to PATH and other environment variables.
> > I don't want the same value to be repeated in the EV. I want to be
> > able to add
> > one digit values (e.g. ".") as wll as longer strings.
> > "." may be translated to "::" (null value) as ":" is used as
> > delimiter.

> > My aproach is a simple function defined within the script or maybe
> > separate in its own file, placed in a directory pointed to by both
> > $PATH and $FPATH.
> > The old way didn't work with "." as argument.
> > The new way don't work at all. (bash:
> > PATH=$PATH:/export/home/ssvedin/bin: A file or directory in the path
> > name does not exist.)
> > Target environment is IBM running AIX 5.2, ksh as well as ksh93 is
> > available.

> It is rather more efficient to use the builtin pattern matching
> available in the shells. Tested with on a debian linux system with
> dash (0.2.45)
> bash (2.05b-2-14)
> ksh93 (Version M 1993-12-28 o+)
> zsh-beta (4.2.0-dev-1+20040423-1)

> postfixpath() {
>    # Append a directory specified by the first parameter
>    # to the environment variable specified by the second parameter
>    # but only if it is not already present. The second parameter
>    # defaults to PATH. Entries are seperated by : characters
>    # Only compares by name, and does not protect against
>    # /usr/bin/., /usr/./bin, /usr//bin, etc
>    # Icarus Sparry - 29 Apr 2004
>    target=${2:-PATH}
>    case "$1" in
>    "")   d="." ;;
>    *:*)    echo "Can not add a directory with a : to $target" >&2
>            return 1 ;;
>    *)      d="$1" ;;
>    esac
>    if [ -d "$d" ] ; then
>            e='case "$'$target'" in
>            "$d"|"$d":*|*:"$d"|*:"$d":*) ;;
>            "")   '$target'="$d" ;;
>            *)      '$target'="$'$target':$d" ;;
>            esac'
>            eval "$e"
>    fi
> }

 
 
 

1. aha2742 boot fail in 88 to 93 kernel!

I just upgraded from the 1.1.88 to the 1.1.93 kernel, and the boot process
stops immediately after printing the message indicating that the kernel
had found my aha274x SCSI controller.  My current configuration,
which hast worked fine from 1.1.71 through 1.1.88 boots from a WD540 IDE
drive partition via lilo, and should find my NEC 3xi CDROM and
Micropolis 1740mb HD on the Adaptec 2742 SCSI chain.

I recompiled the kernel again after uncommenting a couple of #if 0 type
debug statements in the aha274x.c driver source.  This time when I booted
two additional diagnostic messages were printed (I don't remember exactly
what, soming normal looking like  ~"message 0x0 sent..." or something like
that.

Any ideas?

Thanks in advance.

-Jonathan George-

2. Ever Decreasing Memory

3. Flags; bus-master 1, dirty 88(8) current 88(8) ???

4. NT vs. Linux kernel capability

5. ksh-88 parameter expansion

6. Verite/Rendition drivers (Linux, XFree) ?

7. KSH 88 help requested

8. What's filename.tar.Z ?

9. substitute string for pattern in KSH 88

10. Bug in ksh 88[df] "print -u2" and/or "read" statement.

11. ksh-88 parameter expansion

12. put time in ksh PS1: Examples on Kornshell book page 88 does not work

13. Bug in ksh 88[df] "print -u2" and/or "read" statement?