make and change into a directory
Sy Ali
sy1234-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Sat May 20 11:45:29 UTC 2006
On 5/19/06, Giles Orr <gilesorr-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> On 5/19/06, Sy Ali <sy1234-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> > I guess my question is:
> > How can I make an alias do two things?
>
> Good question! Fun for the whole family ...
>
> $ alias a2e="echo -$1-; echo _$1_"
> $ a2e blah
> --
> __ blah
I noticed this. I scratched my head and continued searching for
answers. I figured that $1 was only available once in this context.
> In the bash man page it says "There is no mechanism for using
> arguments in the replacement text. If arguments are needed, a
> shell function should be used (see FUNCTIONS below)." I took the
> hint:
I saw this, but at this point I threw my hands up at the docs for
being unhelpful. I should have read up on functions, but I wanted
more examples without needing to learn too much from scratch.
> $ function f2e () { echo -$1-; echo _$1_; }
> $ f2e blah
> -blah-
> _blah_
>
> Success? "function mcd () { mkdir $1; cd $1; }" does appear to work
> as requested. Please note that the trailing semicolon is required.
Aah. In Behdad's example there was an extra carriage return like so:
mcd() {
mkdir "$1"
cd "$1"
}
so perhaps this functionality carried over in the single-line version of it.
.. It seems that I'm forced to learn bash stuff, because a lot of its
quirks carry over into the commandline tools I'm beginning to build
(in Ruby).
Thanks a lot for the insight.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list