I/O redirection.
Examples
# < input.txt
%Redirect{
direction: :input,
fd: 0,
target: {:file, %Word{parts: [{:literal, "input.txt"}]}}
}
# > output.txt
%Redirect{
direction: :output,
fd: 1,
target: {:file, %Word{parts: [{:literal, "output.txt"}]}}
}
# >> append.txt
%Redirect{
direction: :append,
fd: 1,
target: {:file, %Word{parts: [{:literal, "append.txt"}]}}
}
# 2>&1 (redirect stderr to stdout)
%Redirect{
direction: :duplicate,
fd: 2,
target: {:fd, 1}
}
# &> all_output.txt (redirect both stdout and stderr)
%Redirect{
direction: :output,
fd: :both,
target: {:file, %Word{parts: [{:literal, "all_output.txt"}]}}
}
# <<EOF (heredoc)
# content
# EOF
%Redirect{
direction: :heredoc,
fd: 0,
target: {:heredoc, %Word{parts: [{:literal, "content\n"}]}, "EOF", false}
}
# <<< "string" (herestring)
%Redirect{
direction: :herestring,
fd: 0,
target: {:word, %Word{parts: [{:literal, "string"}]}}
}
Summary
Types
@type direction() :: :input | :output | :append | :duplicate | :heredoc | :herestring
@type t() :: %Bash.AST.Redirect{ direction: direction(), fd: integer() | :both | {:var, String.t()}, meta: Bash.AST.Meta.t(), target: target() }
@type target() :: {:file, Bash.AST.Word.t()} | {:fd, integer()} | {:heredoc, content :: Bash.AST.Word.t(), delimiter :: String.t(), strip_tabs :: boolean()} | {:word, Bash.AST.Word.t()}