Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the --pretty-print option of Bash 5.0 used for?

Tags:

bash

With Bash 5.0:

$ bash --help
GNU bash, version 5.0.0(1)-release-(x86_64-pc-linux-gnu)
Usage:  bash [GNU long option] [option] ...
    bash [GNU long option] [option] script-file ...
GNU long options:
    --debug
    --debugger
    --dump-po-strings
    --dump-strings
    --help
    --init-file
    --login
    --noediting
    --noprofile
    --norc
    --posix
    --pretty-print
    --rcfile
    --restricted
    --verbose
    --version

What is this --pretty-print option? I can't find it in the Bash 5.0 man page, nor the internet! So mysterious :O

like image 481
pawamoy Avatar asked Apr 08 '19 22:04

pawamoy


People also ask

What does print do in bash?

The bash printf command is a tool used for creating formatted output. It is a shell built-in, similar to the printf() function in C/C++, Java, PHP, and other programming languages. The command allows you to print formatted text and variables in standard output.

How do I print a bash statement?

Typically, when writing bash scripts, we use echo to print to the standard output. echo is a simple command but is limited in its capabilities. To have more control over the formatting of the output, use the printf command. The printf command formats and prints its arguments, similar to the C printf() function.

What does V mean in bash script?

The -v option tells the shell to run in verbose mode. In practice, this means that the shell will echo each command prior to executing the command. This will be useful in locating the line of script that has created an error. We can enable the script execution with the -v option as follows: $ bash -v hello.sh.

What is %q in printf?

Characters in the format string are copied to the output or, if a % is encountered, are used to format an item. In addition to the standard formats, %b causes printf to expand backslash escape sequences (for example \n for newline), and %q outputs an item that can be used as shell input.


1 Answers

Found it 8)

In code source, CWRU/changelog line 1427:

shell.c
    - --pretty-print: new invocation option, currently undocumented, dumps
      a pretty-printed version of a shell script given as an argument to
      stdout

I just tried it, it works like type with functions but for entire scripts! Neat. Comments will be removed though!

like image 178
pawamoy Avatar answered Oct 19 '22 23:10

pawamoy