Skip to main content

bash_function_body

Function bash_function_body 

Source
pub fn bash_function_body(name: &str, body_lines: &str) -> String
Expand description

Re-lay a deparsed function body in bash’s type format.

bash re-prints the parsed function from its own AST (make_command_string): the header is NAME () then { — each with ONE trailing space — statements are indented four spaces per level, and every line but the last carries a trailing ;.

$ bash -c 'f() { echo a; echo b; }; type f' | cat -e
f is a function$
f () $
{ $
    echo a;$
    echo b$
}$

body_lines is zsh’s own rendering of the body (one statement per line, one leading TAB per nesting level, keywords on their own lines). BashDeparse re-lays if/for/while/until/select/case, ( ), { } and nested function definitions in bash’s layout; a body with a shape it does not model (here-documents) falls back to the flat one-line-per-statement layout.