help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a function with a shorter name


From: michael-franzese
Subject: Re: Calling a function with a shorter name
Date: Wed, 14 Apr 2021 04:18:33 +0200

> Sent: Wednesday, April 14, 2021 at 2:07 PM
> From: "Eli Schwartz" <eschwartz@archlinux.org>
> To: help-bash@gnu.org
> Subject: Re: Calling a function with a shorter name
>
> On 4/13/21 9:52 PM, michael-franzese@gmx.com wrote:
> >
> > Have written a function with a long name.  I want to use it with a very
> short
> > name somewhere else to improve readability.  Have looked into the command 
> > alias,
> > but I get "command not found" when I call the shorter version.
>
> Did you actually look at which command is not being found? Did you *tell
> us* which command is not being found? This is important information,
> albeit information which some people know to expect.

./tools.sh: line 488: ct: command not found
./tools.sh: line 488: ct: command not found
./tools.sh: line 488: ct: command not found
./tools.sh: line 489: ct: command not found
./tools.sh: line 489: ct: command not found
./tools.sh: line 489: ct: command not found


> Why are you using aliases in scripts anyway?
>
> > ----- tools.sh -----
> > chtcolr () { ... }
> > alias ct='chtcolr'
> > ----- tools.sh -----
> >
> > ----- test.sh -----
> > source ./tools.sh
> > ct $a $b
> > ----- test.sh -----
>
> The actual reproducing case you showed here does not require creating a
> chtcolr function, just name it "ct" when you create it.
>
> Or, since it is a script and length is irrelevant and saving 5 bytes in
> your script isn't a huge efficiency saver, just use the full name.

It is not really about saving a few bytes, but because it also takes parameters
and have the call chtcolr several times, I could use a shortcut and just add a
comment that I am calling chtcolr.

If I simply call it 'ct', everything becomes very cryptic.

> ...
>
> Or, read the bash manpage, section "ALIASES", take note of paragraph 4.
>
> --
> Eli Schwartz
> Arch Linux Bug Wrangler and Trusted User
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]