by Wandfarbe · 6y ago · 0 comments
I just wanna write a few small lines of a shell script which downloads stuff;
It is very very stupid through what loops you hvae to jump to do this with curl and bash script in a good way including readability and error handling.
Is a perl script really better?
Perl 5,6 and 7 did not make it very sane to me, managing and installing and working with perl is also less trivial then having a shell like bash, sh or dash available to you.
Something inbetween bash and go is missing, i like the approach of crush. I think thats the biggest misstake happening in bash: playing around with strings and auto expansion and substition etc. Its weird, its error prone, it doesn't have a proper clean well defined ecosysem.
You don't lose much in terms of shell interop though - the native exec command understands a lot of the basics (file redirection, pipelining, background execution). In the simplest case, it's just one more word:
exec wget $URL
You do have simple exceptions too, which terminate by default unless you catch
them (unfortunately, the stack traces aren't really useful). AFAIK exec throws
on a non-zero exit, and you can use it in your own code too: # Dead
error "IO error"
# Not dead
if {catch [error "IO error"] error_or_result} {
# The error
puts "Caught: $error_or_result"
} else {
# The result
puts "OK: $error_or_result"
}