4 ms·
> as terrible as a shell scripting language That's a strong opinion. I'm not going to argue for lack of time, but suffice to say that 99% of my interactions wi
by jolmg 8y ago
> as terrible as a shell scripting language
That's a strong opinion. I'm not going to argue for lack of time, but suffice to say that 99% of my interactions with my computer and sometimes with my phone is with a shell scripting language. Shell scripting is awesome.
> Have you ever read through a gnu configure file yourself,
Yes. Generated scripts make for a boring read.
> or do you just close your eyes and type "./configure"?
I do, from people I chose to trust, whether by running the package build scripts written by the package maintainers of my distribution or from github accounts that I judge as trustworthy.
There is a lot of trust involved in using a computer. I mean, if something nefarious might be in the ./configure script, it's more likely to also be in a precompiled program, since more people touched it.
> Who in their right mind would ever write a shell script,
I do.
> when there are so many real scripting languages that don't terribly suck universally available,
Each language is good for different reasons. Shell languages are meant primarily to be used interactively, as opposed to languages like python or ruby. The fact that you can put your everyday interactions in a file and run that is an added bonus.
> that don't shit themselves when they encounter a file name with a space in it?
I rather not have filenames with spaces if it means having a language that allows me to communicate with my machine in a terse manner, allowing for super-easy automation of all sorts of interactions.
I mean, are you really suggesting to mandate quoting of all strings in a shell language? The quotes are optional. That's good! In a shell language, files are basically your variables, so why would you want more syntax around your variables when working interactively?
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- njepa 8y ago> That's a strong opinion. I'm not going to argue for lack of time, but suffice to say that 99% of my interactions with my computer and sometimes with my phone is with a shell scripting language. Shell scripting is awesome. It really isn't though. (It certainly can be fun however). Switching from shell scripts, and avoiding to do things manually (like ssh), likely increases your success rate at managing *nix by orders of magnitude. All these "configuration management" tools like Puppet, Chef, SaltStack, Ansible etc. are pretty much just to avoid shell scripts and interactive ssh.
- jolmg 8y ago> All these "configuration management" tools like Puppet, Chef, SaltStack, Ansible etc. are pretty much just to avoid shell scripts and interactive ssh. That's only true if your only use of the shell is for configuration, which isn't really intended to be the case. The shell was meant for any use of the computer, not just configuration. For example, I use ssh/scp when I copy some music files from my computer to my phone, or mpv when I want to play some music files. Indeed, I use the shell for nearly everything.
- overgard 8y agoOh god there's so many easy reasons why bash is terrible. * Significant whitespace in surprising ways (a=1 vs a = 1 or spaces following square brackets) * Word splitting * No data structures of note, nor any way to create them in any sort of non-hacky way * No data types, really, for that matter * Can't really deal with binary data * Awful error handling * Weak math * Weird scoping rules Honestly as soon as I have to do anything that involves a conditional I abandon bash and use one of the many ubiquitous scripting languages that has great library support for doing all the system stuff you could do from the command line anyway. Here's a great list of BASH pitfalls: https://mywiki.wooledge.org/BashPitfalls https://mywiki.wooledge.org/BashPitfalls I can't think of any language other than maybe Perl or C++ that comes close to that
- jolmg 8y agoThey all have reasons. > * Significant whitespace in surprising ways (a=1 vs a = 1 or spaces following square brackets) Variables in the shell are nicely coupled with environment variables. As a feature, you can do: a=1 b=2 cmd to concisely assign environment variables for a single command. How would you recommend that be redone? You'd need additional cumbersome syntax if you want whitespace to not be significant, and that sucks for a language meant to be used mostly interactively: a = 1, b = 2: cmd Because shell languages are meant primarily to be used interactively, we want to be very light on syntax. We don't want to have to say `var` or something before our variable definitions. We don't want to have more syntax than we absolutely need for our calls. Nothing like `cmd(a,b)`. cmd can be any string. They're just executable files in some directory. We want to include as many of them as possible, and their arguments can be anything, including `=`. Commands get as much freedom as possible over how they're called to fit as many needs as possible. So, how do you differentiate between calls and variable assignments? Under those criteria, the current situation of statements being words separated by whitespace and the first words having `=` in them being assignments seems like the ideal solution. > * Word splitting Makes it easier to build commands without working syntax heavy complex data structures. Here's an example where word splitting is useful: sudo strace -f $(printf " -p %s" $(pgrep sshd)) > * No data structures of note, nor any way to create them in any sort of non-hacky way Complex data structure lead to more heavyweight syntax, and part of the appeal of shell languages is that everything is compatible with each other because everything is text. If you add data structures then not everything is text. > * No data types, really, for that matter Same point as above. Everything being text leads to increased compatibility. I wouldn't want to have to convert my data to pass it around. That said, you could say that there are weak-typing semantics, since you can do `$(( $(cmd) + 2 ))`, for example. > * Can't really deal with binary data Because everything is text to encourage easily inspectable data exchange and compatibility between programs. That said, while it's not advisable to do it, binary data is workable if you really need to do that. Pipes don't care. I can pipe music from ssh to ffmpeg to mpv, if I want. One just needs to be careful about doing text-things with it, like trying to pass it as a command argument. $() will remove a terminating newline if present, for example. That makes sense with text, but not with binary data. > * Awful error handling I don't get this. I think bash has very good error handling. Every command has a status code which is either no error or a specific error. Syntax like `while` and `if` work by looking at this status code. You can use `set -e` and subshells to get exception-like behavior. Warnings and error messages are, by default, excluded from being processed through pipes. What do you find lacking? > * Weak math Sure. I'll give you that bash doesn't support fractional numbers natively. zsh does support floating point. > * Weird scoping rules It's dynamic scoping, and it does have some advantages over the more commonly seen static scoping. You can use regular variables to setup execution environments of sorts. This somewhat relieves the need to pass around complex state between functions. It's kind of a different solution to the same problem that objects in OOP address. The only problem is that static scoping became so popular that people now are generally not even aware that dynamic scoping exists or how to use it, so it's now not recommended to use it to not confuse people that don't know that part of the language they're using. About that, I wish people would just learn more of the languages they use, and not expect every language to work the same, as they're not all meant for the same purposes or designed by the same criteria.
- pjmlp 8y ago> Each language is good for different reasons. Shell languages are meant primarily to be used interactively, as opposed to languages like python or ruby. The fact that you can put your everyday interactions in a file and run that is an added bonus. While UNIX was playing with sh, there were already platforms with REPLs, graphical displays and integrated debugger. In fact Jupiter Notebooks are an approximation of that experience. So give me a REPL with function composition and structured data, over pipes and parsing text for the nth time. Thankfully PowerShell now works across all platforms that matter to me.
- deleted 8y ago[deleted]