Class: Ukiryu::Shell::Dash
- Defined in:
- lib/ukiryu/shell/dash.rb
Overview
Dash (Debian Almquist Shell) implementation
Dash is a POSIX-compliant shell that is commonly used as /bin/sh on Debian, Ubuntu, and other Linux distributions. It is similar to bash but more minimal and faster.
Dash uses single quotes for literal strings and backslash for escaping, just like bash. Environment variables use $VAR syntax.
Constant Summary collapse
- SHELL_NAME =
:dash- EXECUTABLE =
'dash'
Constants inherited from UnixBase
Constants inherited from Base
Base::PLATFORM, Base::SPECIAL_CHARS_PATTERN, Base::WHITESPACE_PATTERN
Class Method Summary collapse
-
.detect_alias(command_name) ⇒ Hash?
Detect if a command is a Dash alias.
Instance Method Summary collapse
-
#env_var(name) ⇒ String
Format an environment variable reference.
-
#escape(string) ⇒ String
Escape a string for Dash Single quotes are literal (no escaping inside), so we end the quote, add an escaped quote, and restart the quote.
-
#headless_environment ⇒ Hash
Get headless environment (disable DISPLAY on Unix).
-
#join(executable, *args) ⇒ String
Join executable and arguments into a command line.
- #name ⇒ Object
-
#quote(string) ⇒ String
Quote an argument for Dash Uses single quotes for literal strings (same as bash).
-
#shell_command ⇒ String
Get the dash command name to search for.
Methods inherited from UnixBase
#execute_command, #execute_command_with_stdin, #shell_executable
Methods inherited from Base
#capabilities, #encoding, #environment_to_h, #execute_command, #execute_command_with_stdin, #format_environment, #format_path, #needs_quoting?, #supports?
Class Method Details
.detect_alias(command_name) ⇒ Hash?
Detect if a command is a Dash alias
Dash is POSIX-compliant and uses the same ‘type’ builtin as sh.
23 24 25 26 |
# File 'lib/ukiryu/shell/dash.rb', line 23 def self.detect_alias(command_name) # Dash uses POSIX sh's 'type' builtin Sh.detect_alias(command_name) end |
Instance Method Details
#env_var(name) ⇒ String
Format an environment variable reference
62 63 64 |
# File 'lib/ukiryu/shell/dash.rb', line 62 def env_var(name) "$#{name}" end |
#escape(string) ⇒ String
Escape a string for Dash Single quotes are literal (no escaping inside), so we end the quote, add an escaped quote, and restart the quote. Same as bash.
45 46 47 |
# File 'lib/ukiryu/shell/dash.rb', line 45 def escape(string) string.to_s.gsub("'") { "'\\''" } end |
#headless_environment ⇒ Hash
Get headless environment (disable DISPLAY on Unix)
Dash doesn’t have platform-specific headless behavior, so it returns an empty hash.
81 82 83 |
# File 'lib/ukiryu/shell/dash.rb', line 81 def headless_environment {} end |
#join(executable, *args) ⇒ String
Join executable and arguments into a command line
71 72 73 |
# File 'lib/ukiryu/shell/dash.rb', line 71 def join(executable, *args) [quote(executable), *args.map { |a| quote(a) }].join(' ') end |
#name ⇒ Object
28 29 30 |
# File 'lib/ukiryu/shell/dash.rb', line 28 def name :dash end |
#quote(string) ⇒ String
Quote an argument for Dash Uses single quotes for literal strings (same as bash)
54 55 56 |
# File 'lib/ukiryu/shell/dash.rb', line 54 def quote(string) "'#{escape(string)}'" end |
#shell_command ⇒ String
Get the dash command name to search for
35 36 37 |
# File 'lib/ukiryu/shell/dash.rb', line 35 def shell_command 'dash' end |