Feature #21976
openAdd $SECONDS, $RANDOM, and other bashisms
Description
Some time ago there was a lot of discussion around a script named safe_sleep.sh in the GitHub Actions runner. Like many others, I immediately saw the serious problem with this script: it isn't written in Ruby!
To better support this use case, and to be able to sleep safely, Ruby should support $SECONDS as well as other bashisms like $RANDOM, $1, etc.
This would allow us to rewrite
#!/bin/bash
SECONDS=0
while [[ $SECONDS != $1 ]]; do
:
done
In Ruby
#!/usr/bin/env -S ruby -rbashisms
$SECONDS = 0
while $SECONDS != $1.to_i
;
end
$ ruby -rbashisms -e 'echo $BASH_VERSION'
4.1.2026(4.0.1)-release (ruby)
$ ./safe_sleep.rb 5
For ease of evaluating this proposed feature I've have created the bashisms gem please give it a try!
Updated by AMomchilov (Alexander Momchilov) about 15 hours ago
ยท Edited
Did you think you could fly under the radar with that semi-colon?
That's not acceptable corner to cut.
For proper POSIX shell compatibility, it's imperative that the Ruby grammar be extended to accept : as a bare keyword, equivalent to true. You're in luck, because I've got just the thing! https://github.com/ruby/prism/pull/4056