January 2024
Intermediate to advanced
718 pages
20h 15m
English
If you enclose a string in backquotes (sometimes called backticks) or use the delimited form %x{…}, the string will (by default) be executed as a command by your underlying operating system. The value returned is the standard output of that command. Newlines will not be stripped, so the value you get back will likely have a trailing return or linefeed character.
| | `date` # => "Thu Nov 2 17:16:02 CDT 2023\n" |
| | `ls`.split[34] # => "irb.md" |
| | %x{echo "hello there"} # => "hello there\n" |
You can use expression expansion and all the usual escape sequences in the command string:
| | 0..3.each do |i| |
| | status = `dbmanager status id=#{i}` |
| | # ... |
| | end |
The exit status of the command is available in the global ...
Read now
Unlock full access