Class: Ukiryu::Shell::Dash

Inherits:
UnixBase show all
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

UnixBase::PLATFORM

Constants inherited from Base

Base::PLATFORM, Base::SPECIAL_CHARS_PATTERN, Base::WHITESPACE_PATTERN

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • command_name (String)

    the command to check

Returns:

  • (Hash, nil)

    “…”, target: “…” or nil if not an alias



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

Parameters:

  • name (String)

    the variable name

Returns:

  • (String)

    the formatted reference ($VAR)



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.

Parameters:

  • string (String)

    the string to escape

Returns:

  • (String)

    the escaped string



45
46
47
# File 'lib/ukiryu/shell/dash.rb', line 45

def escape(string)
  string.to_s.gsub("'") { "'\\''" }
end

#headless_environmentHash

Get headless environment (disable DISPLAY on Unix)

Dash doesn’t have platform-specific headless behavior, so it returns an empty hash.

Returns:

  • (Hash)

    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

Parameters:

  • executable (String)

    the executable path

  • args (Array<String>)

    the arguments

Returns:

  • (String)

    the complete 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

#nameObject



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)

Parameters:

  • string (String)

    the string to quote

Returns:

  • (String)

    the quoted string



54
55
56
# File 'lib/ukiryu/shell/dash.rb', line 54

def quote(string)
  "'#{escape(string)}'"
end

#shell_commandString

Get the dash command name to search for

Returns:

  • (String)

    the dash command name



35
36
37
# File 'lib/ukiryu/shell/dash.rb', line 35

def shell_command
  'dash'
end