A post by tedu@ opened my eyes to the function keyword in ksh, which
allows me to fix an annoyance that has bitten me numerous times.
after sourcing /etc/ksh.kshrc,
$ echo $SSH_AUTH_SOCK
/tmp/ssh-IS02tLB2UEAT/agent.19126
$ SSH_AUTH_SOCK= ssh whatever
ssh: Could not resolve hostname whatever: no address associated with name
$ echo $SSH_AUTH_SOCK
$
Thus, the magic ssh wrapping is not invisible, but fucks up my
environment. Using "function" for those indeed give me the way more
expected behaviour:
/tmp/ssh-IS02tLB2UEAT/agent.19126
$ SSH_AUTH_SOCK= ssh whatever
ssh: Could not resolve hostname whatever: no address associated with name
$ echo $SSH_AUTH_SOCK
/tmp/ssh-IS02tLB2UEAT/agent.19126
$
OK?
/Alexander
Index: ksh.kshrc
===================================================================
RCS file: /cvs/src/etc/ksh.kshrc,v
retrieving revision 1.15
diff -u -p -r1.15 ksh.kshrc
--- ksh.kshrc 26 Apr 2010 09:04:15 -0000 1.15
+++ ksh.kshrc 27 Jun 2011 17:38:11 -0000
@@ -92,15 +92,15 @@ case "$-" in
esac
# do we want window decorations?
if [ "$ILS" ]; then
- ilabel () { print -n "${ILS}$*${ILE}">/dev/tty; }
- label () { print -n "${WLS}$*${WLE}">/dev/tty; }
+ function ilabel { print -n "${ILS}$*${ILE}">/dev/tty; }
+ function label { print -n "${WLS}$*${WLE}">/dev/tty; }
alias stripe='label "$USER@$HOST ($tty) - $PWD"'
alias istripe='ilabel "$USER@$HOST ($tty)"'
- wftp () { ilabel "ftp $*"; "ftp" "$@"; eval istripe; }
- wcd () { \cd "$@" && eval stripe; }
- wssh ()
+ function wftp { ilabel "ftp $*"; "ftp" "$@"; eval istripe; }
+ function wcd { \cd "$@" && eval stripe; }
+ function wssh
{
local rc
"ssh" "$@"
@@ -109,7 +109,7 @@ case "$-" in
eval stripe
return $rc
}
- wtelnet ()
+ function wtelnet
{
local rc
"telnet" "$@"
@@ -118,7 +118,7 @@ case "$-" in
eval stripe
return $rc
}
- wrlogin ()
+ function wrlogin
{
local rc
"rlogin" "$@"
@@ -127,7 +127,7 @@ case "$-" in
eval stripe
return $rc
}
- wsu ()
+ function wsu
{
local rc
"su" "$@"
@@ -173,7 +173,7 @@ esac
# commands for both interactive and non-interactive shells
# is $1 missing from $2 (or PATH) ?
-no_path () {
+function no_path {
eval _v="\$${2:-PATH}"
case :$_v: in
*:$1:*) return 1;; # no we have it
@@ -181,15 +181,15 @@ no_path () {
return 0
}
# if $1 exists and is not in path, append it
-add_path () {
+function add_path {
[ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="\$${2:-PATH}:$1"
}
# if $1 exists and is not in path, prepend it
-pre_path () {
+function pre_path {
[ -d ${1:-.} ] && no_path $* && eval ${2:-PATH}="$1:\$${2:-PATH}"
}
# if $1 is in path, remove it
-del_path () {
+function del_path {
no_path $* || eval ${2:-PATH}=`eval echo :'$'${2:-PATH}: |
sed -e "s;:$1:;:;g" -e "s;^:;;" -e "s;:\$;;"`
}