Re: [arch-projects] [dbscripts] [PATCH v2 1/5] Use even more bashisms.
On 02/20/2018 12:24 PM, Emil Velikov wrote: > Seems like I wasn't clear enough: > The goal is not to appease zsh - but a step closer to POSIX sh friendly. > > I've been staring and writing bash (closer to POSIX sh really) scripts > for over a decade, haven't seen what makes X cleaner over Y. > Yet that's subjective, unlike the original argument - consistency rules ;-) If you're working for "POSIX sh friendly", why are you mentioning zsh in the first place? As for targeting POSIX sh, if you can do that then sure. I have personal scripts written for sh when it makes sense (and my /bin/sh is symlinked to dash, so I actually use sh). But yeah, consistency rules. -- Eli Schwartz Bug Wrangler and Trusted User signature.asc Description: OpenPGP digital signature
Re: [arch-projects] [dbscripts] [PATCH v2 1/5] Use even more bashisms.
On 20 February 2018 at 14:23, Eli Schwartzwrote: > On 02/20/2018 06:59 AM, Emil Velikov wrote: >> Disclaimer: the following is a bit subtle topic, so I hope it doesn't >> spur a lot of off-topic. > > Eh, I don't mind. > >> Is there any performance or other technical benefit to using more bashisms? >> >> Reason being, that I am slowly going through different parts of Arch >> making it zsh friendly. >> While keeping the code brief and legible, of course. >> Guessing that I've picked the wrong hobby? > > I think you'll probably find that few people write zsh scripts for > non-interactive use. I'm not really sure what the point would be, > considering it has a nonstandard syntax (bash is ubiquitous, zsh is > not), and many people who would know bash would not know zsh (like me > for example). > > AFAIK zsh should more or less run either bash or POSIX sh scripts just > fine if you invoke it via a symlink named `sh` or `bash`, because zsh > has a bash compatibility mode. I have no idea whether that bash > compatibility mode fixes subtle things like the fact that zsh arrays are > 1-indexed while bash arrays are 0-indexed, but if I had to guess, > probably not. > > ... > > I can see some compelling reasons to write scripts targeting POSIX sh as > a baseline, which is being *sh* friendly, not zsh friendly. > But, for projects that make heavy use of bashisms anyways, I dislike > using POSIX because it implies that sh will be supported in any way when > it really won't be. Essentially, I prefer to go "all in". > > As for why you'd want them, bashisms generally look cleaner IMHO, and > they add a great deal of power and flexibility to the shell. Things like > [[ ... ]] are just a lot more sane in basically every way, shell > arithmetic uses proper operators, etc. > Seems like I wasn't clear enough: The goal is not to appease zsh - but a step closer to POSIX sh friendly. I've been staring and writing bash (closer to POSIX sh really) scripts for over a decade, haven't seen what makes X cleaner over Y. Yet that's subjective, unlike the original argument - consistency rules ;-) Thanks Emil
Re: [arch-projects] [dbscripts] [PATCH v2 1/5] Use even more bashisms.
On 02/20/2018 06:59 AM, Emil Velikov wrote: > Disclaimer: the following is a bit subtle topic, so I hope it doesn't > spur a lot of off-topic. Eh, I don't mind. > Is there any performance or other technical benefit to using more bashisms? > > Reason being, that I am slowly going through different parts of Arch > making it zsh friendly. > While keeping the code brief and legible, of course. > Guessing that I've picked the wrong hobby? I think you'll probably find that few people write zsh scripts for non-interactive use. I'm not really sure what the point would be, considering it has a nonstandard syntax (bash is ubiquitous, zsh is not), and many people who would know bash would not know zsh (like me for example). AFAIK zsh should more or less run either bash or POSIX sh scripts just fine if you invoke it via a symlink named `sh` or `bash`, because zsh has a bash compatibility mode. I have no idea whether that bash compatibility mode fixes subtle things like the fact that zsh arrays are 1-indexed while bash arrays are 0-indexed, but if I had to guess, probably not. ... I can see some compelling reasons to write scripts targeting POSIX sh as a baseline, which is being *sh* friendly, not zsh friendly. But, for projects that make heavy use of bashisms anyways, I dislike using POSIX because it implies that sh will be supported in any way when it really won't be. Essentially, I prefer to go "all in". As for why you'd want them, bashisms generally look cleaner IMHO, and they add a great deal of power and flexibility to the shell. Things like [[ ... ]] are just a lot more sane in basically every way, shell arithmetic uses proper operators, etc. -- Eli Schwartz Bug Wrangler and Trusted User signature.asc Description: OpenPGP digital signature
Re: [arch-projects] [dbscripts] [PATCH v2 1/5] Use even more bashisms.
On Tue, Feb 20, 2018 at 11:59:49AM +, Emil Velikov via arch-projects wrote: > Hi Eli, > > Disclaimer: the following is a bit subtle topic, so I hope it doesn't > spur a lot of off-topic. > > On 19 February 2018 at 20:11, Eli Schwartz via arch-projects >wrote: > > Catch some cases that were missed in the previous run. > > > > Signed-off-by: Eli Schwartz > > --- > > > > This patch is new + refactor some changes from: > > ftpdir-cleanup,sourceballs: replace external find command with bash globbing > > > > cron-jobs/devlist-mailer | 6 +++--- > > cron-jobs/ftpdir-cleanup | 14 +++--- > > cron-jobs/integrity-check | 2 +- > > cron-jobs/sourceballs | 12 ++-- > > cron-jobs/update-web-db | 6 +++--- > > 5 files changed, 20 insertions(+), 20 deletions(-) > > > Is there any performance or other technical benefit to using more bashisms? The scripts run under bash, so why not take advantage of bash features? For example, bash's [[ and (( are less error prone and more featureful than the POSIX [, and builtins like mapfile and read (POSIX read has an extremely limited featureset) make I/O far simpler tasks. There's plenty more to like... Please don't try to talk about performance and shell in the same sentence. These are not performance-sensitive scripts, and shell is not a language to use when performance (of almost any kind) is relevant. > Reason being, that I am slowly going through different parts of Arch > making it zsh friendly. > While keeping the code brief and legible, of course. Feel free to exemplify how conversion from bash to zsh has aided your goals while retaining portability to a supermajority of Arch systems. $ pacman -Q zsh error: package 'zsh' was not found > Guessing that I've picked the wrong hobby? Almost certainly. > Thanks > Emil
Re: [arch-projects] [dbscripts] [PATCH v2 1/5] Use even more bashisms.
Hi Eli, Disclaimer: the following is a bit subtle topic, so I hope it doesn't spur a lot of off-topic. On 19 February 2018 at 20:11, Eli Schwartz via arch-projectswrote: > Catch some cases that were missed in the previous run. > > Signed-off-by: Eli Schwartz > --- > > This patch is new + refactor some changes from: > ftpdir-cleanup,sourceballs: replace external find command with bash globbing > > cron-jobs/devlist-mailer | 6 +++--- > cron-jobs/ftpdir-cleanup | 14 +++--- > cron-jobs/integrity-check | 2 +- > cron-jobs/sourceballs | 12 ++-- > cron-jobs/update-web-db | 6 +++--- > 5 files changed, 20 insertions(+), 20 deletions(-) > Is there any performance or other technical benefit to using more bashisms? Reason being, that I am slowly going through different parts of Arch making it zsh friendly. While keeping the code brief and legible, of course. Guessing that I've picked the wrong hobby? Thanks Emil