Skip to content

Instantly share code, notes, and snippets.

@ChristopherA
Last active November 30, 2019 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristopherA/3eb3f232a5d474e7f9e9737b51a31a77 to your computer and use it in GitHub Desktop.
Save ChristopherA/3eb3f232a5d474e7f9e9737b51a31a77 to your computer and use it in GitHub Desktop.
example(): bash function to create a nicely formatted example of a shell command and its output #bash #tutorial #document

example(): bash function to create a nicely formatted example of a shell command and its output.

example() { echo "EXAMPLE:"; echo; echo " $@"; echo; echo "OUTPUT:"; echo ; eval "$@" | sed 's/^/ /'; }

Sample Output:

EXAMPLE:

    example ls -l

OUTPUT:

    EXAMPLE:
    
        ls -l
    
    OUTPUT:
    
        total 0
        -rw-rw-r-- 1 bartonc bartonc 0 Nov 10 13:58 a
        -rw-rw-r-- 1 bartonc bartonc 0 Nov 10 13:58 b
        -rw-rw-r-- 1 bartonc bartonc 0 Nov 10 13:58 c

First seen: https://www.commandlinefu.com/commands/view/24726/create-a-nicely-formatted-example-of-a-shell-command-and-its-output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment