Thread View: comp.unix.shell
5 messages
5 total messages
Started by Rob Freyder
Thu, 06 Dec 1990 00:48
Passing parameters to an alias in ksh ...under AIX
Author: Rob Freyder
Date: Thu, 06 Dec 1990 00:48
Date: Thu, 06 Dec 1990 00:48
14 lines
1154 bytes
1154 bytes
I am trying to pass a parameter to an alias under AIX on the RS6000. I would like to set up an alias that will take a directory name as an argument and then print that in the title of my X window. I am not having trouble changing the title ... that is a simple escape sequence. My Problem is that I cant get the alias to accept a parameter. I am using $1 to reference the first parameter... Is this correct ? Thanks. Rob. -- ____ ____ ____ Core Lab - Western Atlas Int'l INC \ \ / /\ / \ Rob Humans (318) 235-9431 \ / /\ \/ /\ \ Freyder Internet rob@lafayet.waii.com \/___/ \/___/ \__\ Bang ...!uunet!lafayet!rob
Re: Passing parameters to an alias in ksh ...under AIX
Author: Alan M. Carroll
Date: Thu, 06 Dec 1990 23:54
Date: Thu, 06 Dec 1990 23:54
39 lines
1742 bytes
1742 bytes
In article <1235@lafayet.UUCP>, rob@lafayet.UUCP (Rob Freyder) writes:
> I am trying to pass a parameter to an alias under AIX on the RS6000.
You cannot access parameters in ksh alias's as you can in csh. What
you want is a function, instead. Here is my code to set my xterm
title:
# <ESC> ] 0 ; string <BEL> and string will become the title and icon name
# <ESC> ] 1 ; string <BEL> for icon name only
# <ESC> ] 2 ; string <BEL> for title name only
# control codes removed - you'll have to fix them on your end.
XTITLEPRE="^[]2;"
XICONPRE="^[]1;"
XPOST="^G"
unalias cd
function CD
{
\cd $@
PRWD=${PWD##${HOME}}
if [ ! "${PRWD}" = "${PWD}" ] ; then
PRWD="~$PRWD"
fi
if [[ "$TERM" = "xterm" && "$NOXTITLE" = "" ]] ; then
print -n -r "${XTITLEPRE}${XTITLE}${PRWD}@${HOST}${XPOST}"
fi
}
alias cd=CD
# Fix up the icon title just once, with the host.
if [ "$TERM" = "xterm" ] ; then
print -n -r "${XICONPRE}${HOST}${XPOST}"
fi
--
Alan M. Carroll "It's psychosomatic. You need a lobotomy.
Epoch Development Team I'll get a saw."
CS Grad / U of Ill @ Urbana ...{ucbvax,pur-ee,convex}!cs.uiuc.edu!carroll
Re: Passing parameters to an alias in ksh ...under AIX
Author: The Grey Wolf
Date: Thu, 13 Dec 1990 01:52
Date: Thu, 13 Dec 1990 01:52
44 lines
2439 bytes
2439 bytes
In article <1235@lafayet.UUCP> rob@lafayet.UUCP (Rob Freyder) writes:
>I am trying to pass a parameter to an alias under AIX on the RS6000.
>I would like to set up an alias that will take a directory name as an
>argument and then print that in the title of my X window. I am not having
>trouble changing the title ... that is a simple escape sequence.
>
>My Problem is that I cant get the alias to accept a parameter. I am using
>$1 to reference the first parameter... Is this correct ?
>
>Thanks. Rob.
You don't use aliases for this under ksh -- you use functions, like so:
foo()
{
if [ "$1" = "bar" ] ; then
echo "and grill :-)"
fi
}
The positional parameters are interpreted in the context of the function;
that is, none of the original "$@" is visible to the function unless ex-
plicitly passed.
If your ksh doesn't support functions it is most distinctly broken.
[ I use ksh only when csh is not available. Having to type "fg %2" is
a minor annoyance. Not having the set notation (such as {cat,man,do}_box
expanding to cat_box man_box do_box) is a major annoyance. The command
line editing is cute, but my fingers can figure out csh history quicker.
The delays in ksh due to overhead in the shell (as compared to csh's
overhead) are just noticeable enough to be a nuisance. Beats the HELL
out of sh, though. ]
>--
> ____ ____ ____ Core Lab - Western Atlas Int'l INC
> \ \ / /\ / \ Rob Humans (318) 235-9431
> \ / /\ \/ /\ \ Freyder Internet rob@lafayet.waii.com
> \/___/ \/___/ \__\ Bang ...!uunet!lafayet!rob
--
On the 'Net: Why are more and more fourth-level wizard(-wannabe)s trying to
invoke ninth-level magic, instead of taking the time to climb the other
(quite essential) thirteen levels so they can do this properly?
...!{ucbvax,acad,uunet,amdahl,pyramid}!unisoft!greywolf
Re: Passing parameters to an alias in ksh ...under AIX
Author: Wm E. Davidsen Jr
Date: Thu, 13 Dec 1990 15:30
Date: Thu, 13 Dec 1990 15:30
16 lines
1284 bytes
1284 bytes
In article <3272@unisoft.UUCP> greywolf@unisoft.UUCP (The Grey Wolf) writes:
| If your ksh doesn't support functions it is most distinctly broken.
|
| [ I use ksh only when csh is not available. Having to type "fg %2" is
| a minor annoyance. Not having the set notation (such as {cat,man,do}_box
| expanding to cat_box man_box do_box) is a major annoyance.
To misquote you, "If your ksh doesn't support brack matching it's
seriously broken." Actually just compiled with the BRACE_PAT set to
zero, if I remember the nomencature correctly.
--
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
sysop *IX BBS and Public Access UNIX
moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me
Re: Passing parameters to an alias in ksh ...under AIX
Author: Don Mullins
Date: Wed, 19 Dec 1990 18:34
Date: Wed, 19 Dec 1990 18:34
91 lines
3545 bytes
3545 bytes
In article <1235@lafayet.UUCP> rob@lafayet.UUCP (Rob Freyder) writes:
>I am trying to pass a parameter to an alias under AIX on the RS6000.
>I would like to set up an alias that will take a directory name as an
>argument and then print that in the title of my X window. I am not having
>trouble changing the title ... that is a simple escape sequence.
>
>My Problem is that I cant get the alias to accept a parameter. I am using
>$1 to reference the first parameter... Is this correct ?
>
>Thanks. Rob.
>--
> ____ ____ ____ Core Lab - Western Atlas Int'l INC
> \ \ / /\ / \ Rob Humans (318) 235-9431
> \ / /\ \/ /\ \ Freyder Internet rob@lafayet.waii.com
> \/___/ \/___/ \__\ Bang ...!uunet!lafayet!rob
I don't know how to pass args to an alias (similar to !* in csh/tcsh), but
you can in a function. The following function will cd to the arg passed.
Then it will update the title line if you are running X windows, otherwise
it will change the prompt to reflect the cwd.
It optimizes the path by substituting a '~' for the user's home.
Our version of ksh accepts '\033' of ESC and '\007' for BEL; substitute the
actual chars if needed.
The "$@" in the cd command is equiv. to "$1" "$2" ...
"$*" could be used to get "$1d$2d$3d"... where d is the IFS variable.
both functions assume:
$HOST = hostname (i.e. "starman" for my machine).
$HOME = user's home dir.
$PWD = present working dir.
use by:
<filename>
alias cd=_cd
cd <dir>
--------------------------------- CUT HERE ------------------------------------
function _cd {
# I use the if to prevent the update if the cd fails
if 'cd' "$@"
then
if [ "$DISPLAY" != "" ]
then
# We are running X, update the title line
case "$PWD" in
${HOME}*) XTITLE="${HOST}:~${PWD#"$HOME"}" ;;
*) XTITLE="${HOST}:${PWD}" ;;
esac
print -n "\033]2; ${XTITLE} \007"
else
# Just a terminal, reset the prompt
case "$PWD" in
${HOME}*) PS1="${HOST}:~${PWD#"$HOME"} $ " ;;
*) PS1="${HOST}:${PWD} $ " ;;
esac
fi
fi
}
--------------------------------- END HERE ------------------------------------
This one just sets the title line...
use by:
<filename>
title <text>
--------------------------------- CUT HERE ------------------------------------
function title {
case "$PWD" in
${HOME}*) XTITLE="${HOST}:~${PWD#"$HOME"}" ;;
*) XTITLE="${HOST}:${PWD}" ;;
esac
print -n "\033]2; ${XTITLE} \007"
}
--------------------------------- END HERE ------------------------------------
Let me know if someone shows you how to get an alias to directly accept args.
Good luck,
Don
--
Don Mullins
INTERNET -- mullins@convex.com
UUCP ------ {uiucuxc, uunet, sun, ...}!convex!mullins
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads