|
|
|
|
|
by lhoursquentin
2131 days ago
|
|
The thing is when you restrict yourself to only what POSIX specifies you don't even have basic data structures, no array, no hash map not even local variables, and that often leads to code that relies on multiple hacks. For instance: you can't even slice "$@" which is the only array like construct specified by POSIX (excluding unsafe splitting), so you end up shifting and re-enqueuing with set -- "$@" "$1", which is unreadable. Want to read a single character? Impossible with the POSIX read, but you can workaround with dd etc. All those workarounds to POSIX limitations are fascinating, but it forces a lot of arcane constructs, that's for sure. And of course this is usually the point where you ask yourself if you've chosen the correct language for the task, but that's another debate. |
|
How is that unreadable? Set all the positional arguments as is, then set the first one again, into new positional arguments. I'm not sure why you want the first arg twice, but thats your call.
Either way, it's hardly unreadable.
> And of course this is usually the point where you ask yourself if you've chosen the correct language for the task, but that's another debate.
It isn't another debate though. It's all the same debate: do you know the language you're reading and/or writing? Do you know what it can do, what it can be pushed to do, and what it really shouldn't do?
Those are all related to the same basic point: if you think Shell is unreadable, I'd suggest it's because you don't know shell.
Remember readable means that you can read and understand it. Not that it's written out in words that someone with on page 1 of "how to program for dummies" can understand.