On Mon, Nov 15, 2021 at 12:40:22AM +0800, 積丹尼 Dan Jacobson wrote: > Man page says: > -v Print shell input lines as they are read. > -x Print commands and their arguments as they are executed. > Perhaps mention that -x and -vx give the same results, often or always. > GNU bash, version 5.1.8
They're extremely different. -v only prints lines when bash reads them from its script. NOT when bash executes them. It prints the line exactly as it's read, without any expansions. -x prints commands that bash EXECUTES. Arguments are expanded, and redirections are not shown. You almost never want -v. It's pretty useless. unicorn:~$ cat foo #!/bin/bash for i in {1..10}; do : stuff done unicorn:~$ bash -v foo #!/bin/bash for i in {1..10}; do : stuff done unicorn:~$ bash -x foo + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff + for i in {1..10} + : stuff In the "bash -v foo" output, you can see each line of the script as it gets read. Bash reads the entire for loop at once, then parses it, then runs it. The -v output shows you NOTHING after the loop has been read. The -x output shows you each iteration of the loop.