home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.bash.bug
- Path: sparky!uunet!cis.ohio-state.edu!cs.mu.oz.AU!kre
- From: kre@cs.mu.oz.AU (Robert Elz)
- Subject: Re: Arguments for subroutines
- Message-ID: <9223701.4748@mulga.cs.mu.OZ.AU>
- Sender: gnulists@ai.mit.edu
- Organization: Computer Science, University of Melbourne, Australia
- References: <9208211821.AA02760@iowa.YP.solsys>
- Distribution: gnu
- Date: Sun, 23 Aug 1992 15:35:29 GMT
- Approved: bug-bash@prep.ai.mit.edu
- Lines: 50
-
- 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
-
-