I promised some #Linux tips so here is the first one:
* AVOID USING SHELL SCRIPTS*
1. It is the matter of time when is will stop working. The point is that your script relies on some system state (files, programs, etc.), but it will change with an update. There is no more `ifconfig` for example.
2. The scripting language is ugly by itself. I can't remember how to write simple IF that checks command output. And error handling is a mess.
What instead? Stay tuned!
The most common use of shell scripts is automation of routine tasks. For this purpose I recommend using Ansible.
* Declarative (forget checks like "if dir not exist -> mkdir -p")
* Reusable (you can write roles and apply them to local machine or remote ones
* Testable (with https://molecule.readthedocs.io)
* Yet another framework you have to learn
* I faced some unpredictable behavior with async tasks ~2 years ago, maybe now it fixed
Try experimenting with it! It is fun and easy =)
The next use case of shell scripts is to write your local utils. As I mentioned earlier, I consider POSIX shells aren't handy enough, so I use #FishShell.
It has more clear syntax and some really nice features: Lists, String manipulations, Math module (you can calculate tan in shell! Yeah!), Colors, Autocomplete based on man pages and Web-UI configurator!
Take a look at my recent fish-script that adds audio tracks to video files (cause VLC can't do this automatically, WTF?):
The last one: Shell scripts in DOCKERFILE.
If you use docker a lot than probably at least one of the following is true:
1. You have images that are based on other images (and those are based on some other)
2. There are a lot of duplication in your Dockerfiles
The advise is simple: get rid of Dockerfiles entirely =)
There is a https://packer.io project that gives you an ability to create images from ansible playbooks directly. You can get the advantage of ansible roles and molecule tests!
@jhulten I totally agree with your statement. My point is that shell scripts are not simple (ugly syntax, non-obvious constructions like this http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02 ) and it's hard to write safe scripts (not impossible, just hard).
Also, there is no test suits for it (or maybe I don't know them).
Typically you can find simpler, more suitable and reliable tools and I want to cover some of them in later toots :)
@bemyak I've been doing some deployment using ansible, but lately I'm a kubernetes convert. For smallish deployment they are super-cool.
You get very nice yaml/json syntax for defining services.
@bemyak i want to try fish shell now, thanks for the learnings!
@equal I'm glad! Hope you'll like it.
Here are few tips:
* There is no Ctrl+R. Instead just type your search pattern and press Up arrow (ex. `push` + up = `git push`)
* "oh my fish" may help with installing new plugins. It is very simple unlike "oh my zsh" which is overwhelmingly complicated (that's why I stop using it)
* `fish_config` command will open shell configuration page in your browser! 😎
This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either! We adhere to an adapted version of the TootCat Code of Conduct and follow the Toot Café list of blocked instances. Ash is the admin and is supported by Fuzzface, Brian!, and Daniel Glus as moderators. Hosting costs are largely covered by our generous supporters on Patreon – thanks for all the help!