5 ms·
> I know a lot of developers who will opt to do all of their scripting in python these days, even putting #!/bin/python3 at the head of a script so that it runs
by lucb1e 4y ago
> I know a lot of developers who will opt to do all of their scripting in python these days, even putting #!/bin/python3 at the head of a script so that it runs through the shell.
...which is exactly what you're meant to do.
This is not an example of how bad Bash it, it shows that you didn't understand what Bash is. It's expected to use various languages to write code on Linux, nobody wants you to do things in a language that wasn't made for the task.
Imagine you had to use Python on the shell and, any time you open a terminal, needed to import os and do something like print(os.path.glob("*")) instead of just opening a terminal and typing "ls" to get your directory listing. Different tools for different jobs.
Also the point they try to make about bash looking like a foreign language and having weird syntax. Yes, that's the thing: it's a very specific thing called a shell, not just any old programming language that you're meant to use for things that are not shell scripts. If Python feels more natural to you, that's probably what you should be using. Don't feel like you need to use Bash for bigger tasks than a few lines of code for no reason other than because you're on a system that has it.
- lucb1e 4y agoTo be fair to OP, I would then go on to label these people as equally ignorant: > A lot of people coming from the Unix-like world of macOS and Linux don't tend to know [PS]. Many people don't know it even exists at all. When I mention the Windows Terminal to people, they think I'm talking about the Windows Command Prompt, a crappy little program I know that PS and the new terminal is not the same as cmd.exe, and that it has advantages like passing objects through pipes instead of stringly typing everything the way that sh-like shells work. But that's about the extent of it. (The powershell command names though, oh boy, even Java method names are better than that.) > PowerShell also runs on Unix-like systems through PowerShell Core I forgot about that. If anyone's interested in this, you may also enjoy learning that you can now run Windows Defender on Linux! And Internet Edgesplorer! The software we've all been waiting for, according to the Microsoft press release :D. These things amuse me to no end, but more seriously, getting to know PS better and trying out this object passing system does sound interesting. Similar to how C# is secretly my favorite language, but it's just not well supported on Linux (mono and .netcore with monodevelop or the electron app called "VS Code" are just not the same as the Windows experience, e.g. Windows Forms and the real Visual Studio being huge omissions for me).
- smoldesu 4y agoYeah. Reading the 3-pipe solution in bash versus 4-pipe solution in Powershell felt like it was verging on parody. Yes, these object-oriented features are nice - but they're something of a self-imposed problem on an OS that's designed like a database. Even the tools we use to parse JSON in bash aren't all that bad, if you can keep yourself grounded in the world of text processing. I'm glad that the OP has a workflow that they like, but I'm not really convinced the grass is greener on the other side. I've used a lot of shells, Powershell doesn't really wow me that much anymore.
- emodendroket 4y agoIf the long command names bother you so much most have short aliases, but it's worth remembering that the short ones are cryptic and not that instructive if you're not already initiated.
- smoldesu 4y agoIt's not that bad. I'm mostly balking at the idea of `ConvertFrom-Json | ForEach-Object { $_.name }` being any easier to remember than `jq '.[].name' -r`. Both examples seem to "convert" text to JSON with a parser, it's like arguing over the difference between awk and catting into grep. Neither really seem more advantageous than the other.
- shortrounddev 4y agoThe point is not about being easy to remember (powershell commands and their args can be autocompleted with tab so memorizing them isn't really important). It's about powershell being the object manipulation environment instead of a 3rd party tool like jq. This makes it easier to do stuff with your data with a .Net powered runtime rather than having to manipulate strings using tools with their own built in languages
- emodendroket 4y agoI find the former much more self-explanatory than the latter but, for instance, can't ForEach-Object be written as for?
- cryptonector 4y ago> > even putting #!/bin/python3 at the head of a script so that it runs through the shell. Uh, not, in that case the shell is not involved at all. The kernel implements shebang and will automatically start the interpreter, whatever it is, without having to go through the shell.
- bombolo 4y agoso, a typical noob. Even though he claims he shined in the operating systems course.
- shortrounddev 4y agoThis was a rude comment, and I think youre better than this
- cryptonector 4y agoMy son shined in that course, but I'd be surprised if he knew this particular bit of trivia.
- bombolo 4y agoso they didn't learn about fork/exec in that course? I don't believe it wasn't mentioned :)
- shortrounddev 4y agoOS class is not about Linux, its about OS theory. You learn the algorithms for priority queues and preempting tasks and even build a simple OS (depending on the class). Very little of it is about how IRL operating systems/kernels like NT or Linux work, though they did use some examples to demonstrate. Forking was more in Systems programming class, but that class was more about C, system calls, linking, and gdb. Not much time was dedicated to the syntax of shell scripts.
- 4y ago
- galleywest200 4y agoI thought we were supposed to be using `#!/usr/bin/env python3` and not `#!/bin/python3`?
- silverwind 4y agoDefintely, `#!/bin/python3` will not work inside venvs, I suppose.
- SAI_Peregrinus 4y agoOr any distro that doesn't put a python3 executable in /bin. Many current distros symlink /bin to /usr/bin, but not all do, and python3 would usually be in /usr/bin. POSIX only requires /usr/bin/env and /bin/sh to exist, every other path you might use in a shebang can be moved around.
- Isognoviastoma 4y agoThere are two commands that do work in shebang: /bin/sh and /usr/bin/env. Everything else will break sooner or later: BSDs, Nix, Linux distros with separate /bin and /usr/bin and so on.
- lucb1e 4y agoCorrect. What OP uses would run on none of the systems I work with as far as I know
- askvictor 4y agoThere _is_ Xonsh, which is Python based shell.
- smcameron 4y ago> even putting #!/bin/python3 at the head of a script so that it runs through the shell. It's not the shell, it's the kernel that interprets the so-called shebang. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/binfmt_script.c#n34 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/lin... Edit: oops, should have previewed, cryptonector beat me to it.
- soraminazuki 4y agoYep, imagine how things would be like if the kernel didn't understand shebangs. exec() calls would fail for non-ELF executables and we'd be devising all sorts of ridiculous workarounds. We're lucky that didn't happen.
- cesarb 4y ago> Yep, imagine how things would be like if the kernel didn't understand shebangs. exec() calls would fail for non-ELF executables and we'd be devising all sorts of ridiculous workarounds. We're lucky that didn't happen. Actually, that did happen. Quoting https://utcc.utoronto.ca/~cks/space/blog/unix/ExecAndShebangHistory https://utcc.utoronto.ca/~cks/space/blog/unix/ExecAndShebang... "In V7 (and versions before it), the exec*() family of system calls only worked on actual binary executables. In order to make shell scripts more or less work, the shell (and I think perhaps some other programs) reacted to an ENOEXEC error by assuming the executable was actually a shell script." And yes, the ridiculous workaround (treating the file as a shell script when it's not an executable) seems to still exist to this day.
- leoh 4y agoDude is productive using Windows. It works well for him. It could be an option for you or anyone else too. You've lost the plot here.
- eviks 4y agoThat "very specific thing" does not imply it should be so bad as to be foreign, you could have your much more ergonomic python in the shell as well without all the bash baggage