Skip to main content
Fixed quotes messing up syntax highlight
Source Link
Volker Siegel
  • 17.7k
  • 6
  • 56
  • 81

The standard method to debug scripts in most Bourne-based shells, like bash is to write set -x at the top of your script. This will make bash more verbose about what's being done/executed, and how arguments are evaluated.

-x  Print commands and their arguments as they are executed.

this is useful for either, the interpreter or inside scripts. For example:

$ find "$fileloc" -type f -prune "$filename" -print
+ find /var/adm/logs/morelogs -type f -prune '-name *.user' -print
find: unknown predicate `'-name *.user'
$ find "$fileloc" -type f -prune $filename -print
+ find /var/adm/logs/morelogs -type f -prune -name '*.user' -print
find: `'/var/adm/logs/morelogs': No such file or directory

In the above we can see why find is failing due some single quotes.

To deactivate the feature, just type set +x.

The standard method to debug scripts in most Bourne-based shells, like bash is to write set -x at the top of your script. This will make bash more verbose about what's being done/executed, and how arguments are evaluated.

-x  Print commands and their arguments as they are executed.

this is useful for either, the interpreter or inside scripts. For example:

$ find "$fileloc" -type f -prune "$filename" -print
+ find /var/adm/logs/morelogs -type f -prune '-name *.user' -print
find: unknown predicate `-name *.user'
$ find "$fileloc" -type f -prune $filename -print
+ find /var/adm/logs/morelogs -type f -prune -name '*.user' -print
find: `/var/adm/logs/morelogs': No such file or directory

In the above we can see why find is failing due some single quotes.

To deactivate the feature, just type set +x.

The standard method to debug scripts in most Bourne-based shells, like bash is to write set -x at the top of your script. This will make bash more verbose about what's being done/executed, and how arguments are evaluated.

-x  Print commands and their arguments as they are executed.

this is useful for either, the interpreter or inside scripts. For example:

$ find "$fileloc" -type f -prune "$filename" -print
+ find /var/adm/logs/morelogs -type f -prune '-name *.user' -print
find: unknown predicate '-name *.user'
$ find "$fileloc" -type f -prune $filename -print
+ find /var/adm/logs/morelogs -type f -prune -name '*.user' -print
find: '/var/adm/logs/morelogs': No such file or directory

In the above we can see why find is failing due some single quotes.

To deactivate the feature, just type set +x.

Source Link
Braiam
  • 36.9k
  • 29
  • 114
  • 176

The standard method to debug scripts in most Bourne-based shells, like bash is to write set -x at the top of your script. This will make bash more verbose about what's being done/executed, and how arguments are evaluated.

-x  Print commands and their arguments as they are executed.

this is useful for either, the interpreter or inside scripts. For example:

$ find "$fileloc" -type f -prune "$filename" -print
+ find /var/adm/logs/morelogs -type f -prune '-name *.user' -print
find: unknown predicate `-name *.user'
$ find "$fileloc" -type f -prune $filename -print
+ find /var/adm/logs/morelogs -type f -prune -name '*.user' -print
find: `/var/adm/logs/morelogs': No such file or directory

In the above we can see why find is failing due some single quotes.

To deactivate the feature, just type set +x.