5 ms·
I think that's a testament to how successful shell scripting is. Somehow you can be really productive and write useful tools without really ever diving deep int
by nickjj 8y ago
I think that's a testament to how successful shell scripting is. Somehow you can be really productive and write useful tools without really ever diving deep into the docs.
I've written literally thousands of lines of shell scripts (maybe even 10k+) across dozens of scripts over the years and I've only really looked at the docs a couple of times. Of course I'm Googling various syntax things that are humanly impossible to remember, but I never once really sat there and combed through all of the docs or even read a book on Bash.
You can't do that with most programming languages.
- DonHopkins 8y agoSome of us actually have to USE shell scripts written by other people who like to brag about only looking at the doc a couple of times, who just copy and paste things they found in outdated pages on google into hodge-podges of frankenscripts, and who then run them as root at regular intervals on unattended servers. It may be care free, fun, and effortless for you, but try being on the receiving end of that behavior some time. RTFM! And if the manual sucks (like the Bash manual), then learn to use another language. Instead of learning to write shell scripts better, people should learn NOT to write shell scripts, and learn a decent scripting language instead. You will find that most decent scripting languages like Python are actually a hell of a lot easier to learn and program and maintain than shell scripts.
- mirkules 8y agoJust to add, I generally prefer shell scripts over Python because it is supported in all my use-cases out-of-the-box. However, I recently discovered the power of Python’s Fabric scripts, and holy cow... the ability to run functions on multiple computers at the same time based on roles is amazing (even if the “join” syntax is cumbersome as hell). I think in general, simple system things should be written as scripts. The moment you realize “this is going to take a LOT of scripting” it’s time to look at Python because chances are there’s a module for that.
- nickjj 8y agoIf you like writing things that you can execute on multiple machines take a look at Ansible. It's a Python based configuration management tool where a majority of what you write is YAML and Jinja 2 templates. But on that note, a majority of my current shell scripts are being used on my dev box to improve my day to day. Things like this: https://github.com/nickjj/invoice https://github.com/nickjj/invoice
- DonHopkins 8y agoHave you ever looked through the Linux source code to see how many lines of code and instructions and data structures and libraries and memory allocations and mappings and system calls and context switches are required to search a path for an executable and fork off and run a Unix process? It really breaks my heart to see stuff like this pointlessly wasting electricity by running on a computer that has its own "mul" instruction -- like forking off a "bc" and sending it a stream of decimal digits over a pipe just to multiply a number by 100: echo " > \$$(echo "100 * ${default_hourly}" | bc -l) 100.00 \$${default_hourly} 50 acme" Don't tell me you prefer writing shell scripts that do simple arithmetic because it's more convenient than using Python. Calling out to awk to do trivial string manipulation may impress you as "amazing" after you've hit the wall trying to convert a string to decimal hours with bash and bc, but do you really enjoy all that noisy cryptic bash syntax with all those carefully orchestrated backslashes, double dollar signs, triple angled brackets, echos and pipes and quotes, nested parens and braces, and mysteriously abbreviated dash-letter parameters, to typing "100 * default_hourly"? At least Python's "*" operator doesn't require a "-l" parameter to figure out how to multiply a number by 100. The process id is not your Linux high score. There's no need to run it up by forking so many processes all the time.
- nickjj 8y ago> echo " > \$$(echo "100 ${default_hourly}" | bc -l) 100.00 \$${default_hourly} 50 acme"* > Don't tell me you prefer writing shell scripts that do simple arithmetic because it's more convenient than using Python. That's not a fair comparison. The code you pasted isn't just doing the calculation. It's dynamically generating a human readable help menu that shows both the input and output of what the script will do. That requires quite a bit more characters and escaping. The "real" calculation to get the hourly is: amount="$(echo "${total_hours} * ${hourly_rate}" | bc -l)" Seems pretty straight forward to me. Plus, that's a really cherry picked example in Python's favor. You should evaluate the whole script's purpose. It's mostly just reading and filtering text output from a file and then performing basic math on the filtered text. Seems like a textbook case to use Bash IMO.
- im3w1l 8y ago> people should learn NOT to write shell scripts, Knowing the basics of shell scripting is not optional. As a dev on a unix system, it's just a question of time before you have to read and tweak other people's scripts.
- deleted 8y ago[deleted]
- DonHopkins 8y agoKnowing how to change a diaper when you're a parent is not optional. But you shouldn't shit your own pants when you don't absolutely need to. You may think you're clever enough to sneak out a little one-liner that nobody will notice, but all too often you underestimate the task, and it blossoms into a big messy shart script that other people have to deal with.
- gumby 8y agoAround 1992 I wrote a CGI at Cygnus for reporting the top high priority and important bugs, who was responsible and how old they were. It was used for years, and people would load that page several times a day as they did not want to have their name at the top of the list! I wrote it in Bash.
- DonHopkins 8y agoAt Sun in 1991, the stupidest thing I ever did was try to use xbugtool to report a bug against itself. https://www.donhopkins.com/home/catalog/unix-haters/x-windows/xbugtool.html https://www.donhopkins.com/home/catalog/unix-haters/x-window... (Well that, and installing Solaris.) https://www.donhopkins.com/home/catalog/unix-haters/slowlaris/worst-job.html https://www.donhopkins.com/home/catalog/unix-haters/slowlari... #!/bin/sh # This works...I wonder if it will get me laid progname="`echo $0 | sed 's:^\./\./:\./:'`"
- dredmorbius 8y agoCirca the same era I wrote some space-management tools in DCL. Got a support call years later when I could no longer spell that. Code can be astonishingly durable.