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
a slightly modified way (two params with the second defaulting toQuote:}
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
the new one:Quote:}
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