Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How do you decide whether to make something a function or a script?
- X-seq: zsh-users 23609
- From: Grant Taylor <gtaylor@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: How do you decide whether to make something a function or a script?
- Date: Sat, 8 Sep 2018 19:55:16 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=tnetconsulting.net; s=2015; t=1536458049; bh=Ku/3iV2Umd1l6KQBl7kNojUVz3Vw2uefuva59XR1iaQ=; h=Subject:To:References:From:Message-ID:Date:User-Agent: MIME-Version:In-Reply-To:Content-Type:Cc:Content-Disposition: Content-Language:Content-Transfer-Encoding:Content-Type:Date:From: In-Reply-To:Message-ID:MIME-Version:References:Reply-To: Resent-Date:Resent-From:Resent-To:Resent-Cc:Sender:Subject:To: User-Agent; b=iOxlUv9pcFlVyG8EeisVP7g4CI73S7tarZ4PdmgXuO53PJKn2nSJE2R3W085qhZsj AVialNvTF/dNXM6ClW/1H32SDnBoYCkFBdP0PVxvW90h9Eih2YSbg25ZQC/hR5oLTh kHACwKftYgifmbbbsTc5BD9faWWtYTsKr9yGEnQ4=
- In-reply-to: <CADjGqHuK2oV3VzjHO0H5+FHJXC85HmysL9yPRjS-ESLhBcC3FA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: TNet Consulting
- References: <CADjGqHuK2oV3VzjHO0H5+FHJXC85HmysL9yPRjS-ESLhBcC3FA@mail.gmail.com>
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:
smime.p7s
Description: S/MIME Cryptographic Signature
Messages sorted by:
Reverse Date,
Date,
Thread,
Author