A shell in Rust could be really cool
A shell in Rust could be really cool
Posted Feb 12, 2025 16:45 UTC (Wed) by wtarreau (subscriber, #51152)In reply to: A shell in Rust could be really cool by dskoll
Parent article: Rewriting essential Linux packages in Rust
A long time ago when I begun with unix, my default shell was tcsh. I didn't understand why some of my scripts didn't work the same way on the command line. I thought this had to do with interactive vs non-interactive. When I realized that the shell was different, I switched to bash and lost a lot of stuff (it was 1.14 by then), but I started to write working scripts. When 2.05b arrived scripting abilities improved a lot! I once tried to switch to zsh because it was compatible with bourne, but admins hated it due to the way it displays completion and moves the screen up. And one difficulty was that you quickly get used to features that again don't work in your portable scripts. So I went back to bash, the (in)famous bug-again-shell that everyone loves to hate. But in the end, scripts written with it work basically everywhere. And if you need to get rid of it because you end up with a real bourne (like dash), that's not that dramatic, you spend a few hours getting rid of bashisms and that's done. Or the user installs bash or ksh, since their compatible subset is quite large.
That's why people continue to write (sometimes long) shell scripts: that's easy, portable and transferable to someone else to take over them. And they come with basically 0 dependencies (aside external programs) so that makes them future-proof contrary to many interpreted languages whose interpreter breaks compatibility, or whose libraries love to change API all the time by adding a new argument to a function...
Posted Feb 13, 2025 9:09 UTC (Thu)
by taladar (subscriber, #68407)
[Link] (7 responses)
Posted Feb 13, 2025 12:50 UTC (Thu)
by pizza (subscriber, #46)
[Link] (6 responses)
This turned out to be the root cause of an infuriating intermittent bug I was trying to figure out -- nobody could give me a reproducible test case. Turns out they were using something other than English locales.
Posted Feb 14, 2025 15:35 UTC (Fri)
by taladar (subscriber, #68407)
[Link] (5 responses)
Posted Feb 14, 2025 23:51 UTC (Fri)
by himi (subscriber, #340)
[Link] (3 responses)
A few simple experiments with bash suggest "08" used in an arithmetic expansion will error ('bash: 08: value too great for base (error token is "08")') - pretty much what I'd expect, though it'd take me by surprise the first time it happened (at least the error is nice and informative). Are you talking about something like iterating through 0-padded numeric months and hitting errors once you hit August?
Posted Feb 15, 2025 0:16 UTC (Sat)
by Wol (subscriber, #4433)
[Link]
Copy a column of date-times from one spreadsheet to another. Format the date-time as a time. Save as a csv. If you're not in America the csv will contain a "random" mix of times and date-times. But all the date-times will not be a valid American date, for example today - 15/02/2025 - will be a date-time, while fast-forward a fortnight to 01/03/2025 and it will be correctly converted to a time.
The fix is easy - explicitly format/force the text into a European date, and everything then works, but it's a pain in the arse. Especially if every time you hit the problem, you've forgotten the previous time ...
Cheers,
Posted Feb 17, 2025 13:42 UTC (Mon)
by taladar (subscriber, #68407)
[Link] (1 responses)
The solution is easy once you know about it, you can simply prefix every variable in the arithmetic expression with 10# to force base 10 but you need to know about.
Posted Feb 18, 2025 21:46 UTC (Tue)
by himi (subscriber, #340)
[Link]
I try to use unix timestamps ($(date +%s)) whenever I'm dealing with times and dates of any sort in shell scripts, and then use $(date -d @...) to convert to something human readable - not particularly portable, but I'm fortunate enough to only really deal with Linux systems (aside from an occasional Mac, which has caused me serious headaches at times).
I do sometimes use sub-second precision (e.g. $(date +%s.%N)) for higher resolution timing, which then necessitates using bc -l or similar for any calculations. That recently bit me, in combination with scoping issues - I was mixing second and sub-second precision and the (perfectly logical) variable name 'now', and getting errors from arithmetic expansions when a sub-second precision value was still active where I thought it should be second precision . . . Fixing that just required fixing the scoping and naming issues ('local' is one of my favourite keywords), but it took *far* to long to spot the bug.
And to bring this back on topic, that's one monstrosity of a shell script that *absolutely* needs to be rewritten - though probably not in Rust, sadly, since I'm the only person in my team who'd have any hope of working on a Rust version . . .
Posted Feb 17, 2025 21:12 UTC (Mon)
by raven667 (subscriber, #5198)
[Link]
A shell in Rust could be really cool
A shell in Rust could be really cool
A shell in Rust could be really cool
A shell in Rust could be really cool
A shell in Rust could be really cool
Wol
A shell in Rust could be really cool
A shell in Rust could be really cool
A shell in Rust could be really cool