Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: exit to shell from nested function calls.



Functions are great, and I recommend using them - just use them _inside_ the script. For anything but the most trivial scripts I make the main body of the script a function, too, something like this:

#!/usr/bin/env zsh
main() {
    main program code here
}

sub1() {
    called by main
}

sub2() {
    called by main or sub1
}
..
... other declarations ...
...
main "$@"
 
Only define functions inside your interactive shell when they need to make changes that persist after they exit - like changing directories, or updating variable values, etc.


On Thu, May 16, 2024 at 5:30 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:


On 2024-05-16 13:26, Roman Perepelitsa wrote:
I'd turn this into a script (executable file) and use exit to bail
out. IMO, anything that can be a script is better off as a script.
I'm slowly figuring that out.  Yes, that's the motivator I need.  Coming from C I just sorta started writing functions cuz that's what one does in C.

Thanks Roman. 

BTW, just in case you're wondering, it's an overlay for mostly firefox which chatters to the disk almost constantly.  Got  a newer machine recently and it has a SSD, but I know they have limited R/W cycles so I'm using the overlay to deflect the chatter to RAM.  Works good so far.  Will try it with a few other progs too, and possibly /var.  It 's interesting watching 'fatrace -fW' for a while -- see who's a disk blabbermouth. 





--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author