Thread View: gnu.bash.bug
2 messages
2 total messages
Started by Kevin Burton
Fri, 21 Aug 1992 18:21
Arguments for subroutines
Author: Kevin Burton
Date: Fri, 21 Aug 1992 18:21
Date: Fri, 21 Aug 1992 18:21
25 lines
1131 bytes
1131 bytes
I have bash-1.12 and am trying to convert some CSH aliases to subroutines
in bash. I want to be able to get at all of the arguments from a specified
argument on (like !:3* in CSH).
foo ()
{
echo $1;
# This of course does not work but I want to be able to do something
# like this.
echo $2*;
}
I have looked on the info pages and found very little documentation at all
on these "subroutines".
Does anyone know how I might do this ? Do I have to concatenate all the the
arguments manually ? I hope not :-(
Thank you.
-
Kevin Burton
Noran Instruments voice: (608) 831-6511 x317
2551 West Beltline Highway, Room 532 FAX: (608) 836-7224
Middleton, WI 53562 email: kburton@noran.com
Re: Arguments for subroutines
Author: Robert Elz
Date: Sun, 23 Aug 1992 15:35
Date: Sun, 23 Aug 1992 15:35
49 lines
1283 bytes
1283 bytes
In <9208211821.AA02760@iowa.YP.solsys> kburton@iowa.UUCP (Kevin Burton) writes:
| I have bash-1.12 and am trying to convert some CSH aliases to subroutines
| in bash. I want to be able to get at all of the arguments from a specified
| argument on (like !:3* in CSH).
Try ...
foo()
{
echo $1
shift
echo $*
}
or if you want $1 later
foo()
{
X=$1
shift
echo $*
echo $X
}
Of course, you can also use $@ instead of $* if that's more suited.
If you need $* put back (for some odd reason "$X $*" is not good enough)
Then you can do
foo()
{
ARGS=
while [ $# -gt 0 ]; do
ARGS="$ARGS '$1'"
shift
done
eval set -$- $ARGS
X=$1
shift
echo $* # to get the ${2:*} effect
shift
echo $* # now ${3:*}
eval set -$- $ARGS # now all args are back as originally
}
kre
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