From: Grant Taylor <gtaylor@tnetconsulting.net>
To: zsh-users@zsh.org
Subject: Re: How do you decide whether to make something a function or a script?
Date: Sat, 8 Sep 2018 19:55:16 -0600 [thread overview]
Message-ID: <c326defd-125c-823b-b281-a26b431e0727@spamtrap.tnetconsulting.net> (raw)
In-Reply-To: <CADjGqHuK2oV3VzjHO0H5+FHJXC85HmysL9yPRjS-ESLhBcC3FA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1288 bytes --]
On 09/08/2018 07:22 PM, TJ Luoma wrote:
> But it's gotten me to wonder:
That can be dangerous. ;-)
> Why make any functions at all? Why not just make them all scripts? If
> they are scripts in the $PATH then you can just call them by name and
> they work in the login shell or in scripts. If they are functions,
> you have to autoload them first.
>
> So I've gotten to wonder… what makes you make something a function vs
> a script?
IMHO it all has to do with scope. I tend to progress along the
following sequence when I have reason to move to the next level:
1) alias
2) function
3) script
IMHO aliases enable me to be lazy and not type things out completely, or
make what seems to be custom commands like; alias myserver='ssh myserver'.
I upgrade from aliases to functions any time I need parameters or I want
scripts to be able to use the same command.
I upgrade from functions to scripts when I want to be able to run the
command from outside of the shell, like an ssh remote command: ssh
myserver openDB. The remote command doesn't launch the shell, thus
doesn't have access to functions, much less aliases. But it does have
access to scripts if I have my PATH configured properly.
--
Grant. . . .
unix || die
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 3982 bytes --]
next prev parent reply other threads:[~2018-09-09 2:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-09 1:22 TJ Luoma
2018-09-09 1:55 ` Grant Taylor [this message]
2018-09-09 2:21 ` Daniel Shahaf
2018-09-09 2:51 ` Grant Taylor
2018-09-09 19:34 ` TJ Luoma
2018-09-09 22:54 ` Bart Schaefer
2018-09-09 3:24 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c326defd-125c-823b-b281-a26b431e0727@spamtrap.tnetconsulting.net \
--to=gtaylor@tnetconsulting.net \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).