Earlier quoted context omitted.
Because it is ubiquitous. You can virtually guarantee that bash will be found on any arbitrary unix-like system.
Same reason I always cook my eggs using a shoe.
Safe ways to do things in bash
181–190 of 255 posts
Re: Safe ways to do things in bash
#182Earlier quoted context omitted.
I probably have a similar history but I've come to the belief that you should not use Bash if you're doing anything fancy or long (>10 lines). Just use Perl, Python or Ruby. One or all of them is installed on every machine you are likely to use.
Is there an easy way to run shell commands in Python, like backticks in PERL, Ruby or even PHP? I'd really like to use Python more often, but most of the time it only complicates things with those verbose syscalls.
Re: Safe ways to do things in bash
#183I've written a ridiculous amount of shell script in my day, especially when doing "devops" before we had a term like "devops" to describe it. I've fallen in almost every pit bash has. With that background, here is my opinion. 1. This article contains excellent advice and should be starred for later retrieval. 2. Having basic scripting skills will make you a way better programmer. Many times I've done huge refactors a…
I think it's time people start using something better than bash/zsh that is decades old, like fish or even come up with a more modern shell. Even by looking at these examples, you see it has less verbosity like "then" and "do", you can reference arguments as $argv instead of cryptic $@ and exit status code as $status instead of $? which is confusing with $! and the likes. https://blog.codeship.com/lets-talk-about-she…
https://github.com/lihaoyi/Ammonite
Many times previously I've starting really quickly testing/prototyping an idea in bash, which eventually grew large and unweildy. Ammonite appears like it might allow quick hacking, but also the option to easily transition your scripts into scala proper while leveraging the good bits of Java.
Re: Safe ways to do things in bash
#184Earlier quoted context omitted.
I probably have a similar history but I've come to the belief that you should not use Bash if you're doing anything fancy or long (>10 lines). Just use Perl, Python or Ruby. One or all of them is installed on every machine you are likely to use.
Is there an easy way to run shell commands in Python, like backticks in PERL, Ruby or even PHP? I'd really like to use Python more often, but most of the time it only complicates things with those verbose syscalls.
Re: Safe ways to do things in bash
#185Earlier quoted context omitted.
Do Makefiles fall under that category?
Chiming in for myself, no. Makefiles are more about dependency graphs and reproducible pipelines. I use them to make more sophisticated things than bash scripts, which are purely imperative. I very much dislike cmake, and I've not yet been impressed by any of the other many Make replacement candidates. How else would you accomplish what a Makefile would?
However, as someone who doesn't write much C, I went back to make. Makefiles seem to adapt really well to different workflows.
A lot of my makefiles look like "download this publically available data, scp this secret data off a company server, mungle all the data with some scripts, shallow clone this branch of that repository, run the program in the repository a few times under different conditions, make a chart of the results".
Tup really doesn't like steps like "clone this repository". Make isn't exactly great with keeping track of targets that output entire directories, but it does work.
I also feel like, for me, make has become more powerful over time as I've learned other tools. Specifically: being able to just magic up any old environment using Nix and be confident that it won't break, mashing data with things like jq, cut, sed and awk, and quick database operations with SQLite.
Re: Safe ways to do things in bash
#186Earlier quoted context omitted.
I think it's time people start using something better than bash/zsh that is decades old, like fish or even come up with a more modern shell. Even by looking at these examples, you see it has less verbosity like "then" and "do", you can reference arguments as $argv instead of cryptic $@ and exit status code as $status instead of $? which is confusing with $! and the likes. https://blog.codeship.com/lets-talk-about-she…
You might find the Oil Blog[0] interesting, there are a lot of interesting thoughts there about what a truly modern shell might look like. [0]: https://www.oilshell.org/blog/
Re: Safe ways to do things in bash
#187Earlier quoted context omitted.
Availability is a big issue. It is nearly impossible to get a seasoned sysadmin to install fish for you when bash is available.
If you're convinced your productivity may change by ditching bash, I'm not sure what kind of counterargument the sysadmin will bring.
Re: Safe ways to do things in bash
#188Earlier quoted context omitted.
You just add quotes around $dir. Bash understands the quotes properly/recursively. parent_dir = "$(basename "$dir")"
So I finally found the answer. Thanks.
Re: Safe ways to do things in bash
#189Earlier quoted context omitted.
Yes, but which one, and which version? This is especially painful with Python ;)
What's painful about Python but not so for others? Writing anything complicated in bash/zsh is painful enough I wouldn't even think about it.
Re: Safe ways to do things in bash
#190Earlier quoted context omitted.
I think a big issue is that bash is available everywhere, while fish might not be. There's also the fact that a lot of us have fancy dotfiles for our work/home computers, and switching to another shell would mean having to rewrite them in the target shell language.
So, you'd rather use something that is decades old because you can't/don't want to (ask to) install 1 new program on the server and take a weekend to rebuild your config file? You can simply import aliases as is and in some cases, you may be able to even simplify parts of your config. Personally, it was easy for me as I'm administering the servers and it was all just installing fish on every servers. (some dozens.)