-
Notifications
You must be signed in to change notification settings - Fork 5
Arguments and Options
Albert Álef edited this page Feb 3, 2026
·
3 revisions
RubyShell provides intuitive argument handling that converts Ruby hashes into command-line flags.
Pass arguments as strings:
sh.git("commit", "-m", "Initial commit")
sh.cp("source.txt", "dest.txt")
sh.mkdir("-p", "path/to/folder")Use single-character symbols or keys:
sh.ls(l: true) # ls -l
sh.git("status", s: true) # git status -s
sh.rm(r: true, f: true) # rm -r -fUse symbols or strings with multiple characters:
sh.docker("ps", all: true) # docker ps --all
sh.git("log", oneline: true) # git log --oneline
sh.grep({ color: "auto" }, "pattern") # grep --color=auto patternsh.git("log", n: 5) # git log -n 5
sh.docker("run", name: "myapp") # docker run --name myapp
sh.curl(o: "output.txt", "url") # curl -o output.txt urlArrays expand into multiple arguments:
sh.git("add", "file1.rb", "file2.rb")
sh.docker({ e: ["VAR1=a", "VAR2=b"] }, "run") # -e VAR1=a -e VAR2=b runCombine positional arguments with flags:
sh.find(".", type: "f", name: "*.rb")
# find . --type f --name "*.rb"
sh.rsync({ a: true, v: true }, "src/", "dest/")
# rsync -a -v src/ dest/Options starting with _ are RubyShell-specific and not passed to the command:
| Option | Description |
|---|---|
_stdin |
Pipe input to the command |
_debug |
Enable debug output for this command |
sh.wc(l: true, _stdin: "line1\nline2\nline3") # wc -l (with stdin)
sh.echo("test", _debug: true) # Shows debug infoNext: Command Chaining