Project

General

Profile

Actions

Feature #21976

open

Add $SECONDS, $RANDOM, and other bashisms

Feature #21976: Add $SECONDS, $RANDOM, and other bashisms
1

Added by jhawthorn (John Hawthorn) about 16 hours ago. Updated about 15 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:125167]

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 Actions #1 [ruby-core:125169]

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

Actions

Also available in: PDF Atom