[ruby-core:125167] [Ruby Feature#21976] Add $SECONDS, $RANDOM, and other bashisms
Issue #21976 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Feature #21976: Add $SECONDS, $RANDOM, and other bashisms https://bugs.ruby-lang.org/issues/21976 * Author: jhawthorn (John Hawthorn) * Status: Open ---------------------------------------- Some time ago there was a lot of discussion around a script named [safe_sleep.sh](https://github.com/actions/runner/blob/af6c8e6eddef233fdef862c1287d9b013c8aa...) in the GitHub Actions runner. Like [many others](https://github.com/actions/runner/issues/2380), 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 ```bash #!/bin/bash SECONDS=0 while [[ $SECONDS != $1 ]]; do : done ``` In Ruby ```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](https://github.com/jhawthorn/bashisms) please give it a try! -- https://bugs.ruby-lang.org/
Issue #21976 has been updated by AMomchilov (Alexander Momchilov). Did you think you could fly under the radar with that semi-colon? That's not acceptable corner to cut. For proper POSIX Bash compatibility, it's imperative that the Ruby grammar be extended to accept `:` as a bare keyword, equivalent to `true`. ---------------------------------------- Feature #21976: Add $SECONDS, $RANDOM, and other bashisms https://bugs.ruby-lang.org/issues/21976#change-116898 * Author: jhawthorn (John Hawthorn) * Status: Open ---------------------------------------- Some time ago there was a lot of discussion around a script named [safe_sleep.sh](https://github.com/actions/runner/blob/af6c8e6eddef233fdef862c1287d9b013c8aa...) in the GitHub Actions runner. Like [many others](https://github.com/actions/runner/issues/2380), 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 ```bash #!/bin/bash SECONDS=0 while [[ $SECONDS != $1 ]]; do : done ``` In Ruby ```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](https://github.com/jhawthorn/bashisms) please give it a try! -- https://bugs.ruby-lang.org/
Issue #21976 has been updated by nobu (Nobuyoshi Nakada). Sorry to be late: https://github.com/nobu/bashism ---------------------------------------- Feature #21976: Add $SECONDS, $RANDOM, and other bashisms https://bugs.ruby-lang.org/issues/21976#change-116916 * Author: jhawthorn (John Hawthorn) * Status: Open ---------------------------------------- Some time ago there was a lot of discussion around a script named [safe_sleep.sh](https://github.com/actions/runner/blob/af6c8e6eddef233fdef862c1287d9b013c8aa...) in the GitHub Actions runner. Like [many others](https://github.com/actions/runner/issues/2380), 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 ```bash #!/bin/bash SECONDS=0 while [[ $SECONDS != $1 ]]; do : done ``` In Ruby ```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](https://github.com/jhawthorn/bashisms) please give it a try! -- https://bugs.ruby-lang.org/
participants (3)
-
AMomchilov (Alexander Momchilov) -
jhawthorn (John Hawthorn) -
nobu (Nobuyoshi Nakada)