| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | #! @PERL@ | | 1 | #! @PERL@ |
2 | # $NetBSD: pkglint.pl,v 1.769 2008/05/21 20:16:19 abs Exp $ | | 2 | # $NetBSD: pkglint.pl,v 1.770 2008/07/25 14:15:44 dillo Exp $ |
3 | # | | 3 | # |
4 | | | 4 | |
5 | # pkglint - static analyzer and checker for pkgsrc packages | | 5 | # pkglint - static analyzer and checker for pkgsrc packages |
6 | # | | 6 | # |
7 | # Written by: | | 7 | # Written by: |
8 | # Roland Illig <rillig@NetBSD.org> | | 8 | # Roland Illig <rillig@NetBSD.org> |
9 | # | | 9 | # |
10 | # Based on work by: | | 10 | # Based on work by: |
11 | # Hubert Feyrer <hubertf@NetBSD.org> | | 11 | # Hubert Feyrer <hubertf@NetBSD.org> |
12 | # Thorsten Frueauf <frueauf@NetBSD.org> | | 12 | # Thorsten Frueauf <frueauf@NetBSD.org> |
13 | # Thomas Klausner <wiz@NetBSD.org> | | 13 | # Thomas Klausner <wiz@NetBSD.org> |
14 | # and others. | | 14 | # and others. |
15 | # | | 15 | # |
| @@ -4446,26 +4446,39 @@ sub checkline_mk_shellword($$$) { | | | @@ -4446,26 +4446,39 @@ sub checkline_mk_shellword($$$) { |
4446 | if ($rest =~ s/^[!#\%&\(\)*+,\-.\/0-9:;<=>?\@A-Z\[\]^_a-z{|}~]+//) { | | 4446 | if ($rest =~ s/^[!#\%&\(\)*+,\-.\/0-9:;<=>?\@A-Z\[\]^_a-z{|}~]+//) { |
4447 | } elsif ($rest =~ s/^\'//) { | | 4447 | } elsif ($rest =~ s/^\'//) { |
4448 | $state = SWST_SQUOT; | | 4448 | $state = SWST_SQUOT; |
4449 | } elsif ($rest =~ s/^\"//) { | | 4449 | } elsif ($rest =~ s/^\"//) { |
4450 | $state = SWST_DQUOT; | | 4450 | $state = SWST_DQUOT; |
4451 | } elsif ($rest =~ s/^\`//) { | | 4451 | } elsif ($rest =~ s/^\`//) { |
4452 | $state = SWST_BACKT; | | 4452 | $state = SWST_BACKT; |
4453 | } elsif ($rest =~ s/^\\(?:[ !"#'\(\)*;?\\^{|}]|\$\$)//) { | | 4453 | } elsif ($rest =~ s/^\\(?:[ !"#'\(\)*;?\\^{|}]|\$\$)//) { |
4454 | } elsif ($rest =~ s/^\$\$([0-9A-Z_a-z]+|\#)// | | 4454 | } elsif ($rest =~ s/^\$\$([0-9A-Z_a-z]+|\#)// |
4455 | || $rest =~ s/^\$\$\{([0-9A-Z_a-z]+|\#)\}//) { | | 4455 | || $rest =~ s/^\$\$\{([0-9A-Z_a-z]+|\#)\}//) { |
4456 | my ($shvarname) = ($1); | | 4456 | my ($shvarname) = ($1); |
4457 | if ($opt_warn_quoting && $check_quoting) { | | 4457 | if ($opt_warn_quoting && $check_quoting) { |
4458 | $line->log_warning("Unquoted shell variable \"${shvarname}\"."); | | 4458 | $line->log_warning("Unquoted shell variable \"${shvarname}\"."); |
| | | 4459 | $line->explain_warning( |
| | | 4460 | "When a shell variable contains white-space, it is expanded (split into", |
| | | 4461 | "multiple words) when it is written as \$variable in a shell script.", |
| | | 4462 | "If that is not intended, you should add quotation marks around it,", |
| | | 4463 | "like \"\$variable\". Then, the variable will always expand to a single", |
| | | 4464 | "word, preserving all white-space and other special characters.", |
| | | 4465 | "", |
| | | 4466 | "Example:", |
| | | 4467 | "\tfname=\"Curriculum vitae.doc\"", |
| | | 4468 | "\tcp \$fname /tmp", |
| | | 4469 | "\t# tries to copy the two files \"Curriculum\" and \"Vitae.doc\"", |
| | | 4470 | "\tcp \"\$fname\" /tmp", |
| | | 4471 | "\t# copies one file, as intended"); |
4459 | } | | 4472 | } |
4460 | | | 4473 | |
4461 | } elsif ($rest =~ s/^\$\@//) { | | 4474 | } elsif ($rest =~ s/^\$\@//) { |
4462 | $line->log_warning("Please use \"\${.TARGET}\" instead of \"\$@\"."); | | 4475 | $line->log_warning("Please use \"\${.TARGET}\" instead of \"\$@\"."); |
4463 | $line->explain_warning( | | 4476 | $line->explain_warning( |
4464 | "It is more readable and prevents confusion with the shell variable of", | | 4477 | "It is more readable and prevents confusion with the shell variable of", |
4465 | "the same name."); | | 4478 | "the same name."); |
4466 | | | 4479 | |
4467 | } elsif ($rest =~ s/^\$\$\@//) { | | 4480 | } elsif ($rest =~ s/^\$\$\@//) { |
4468 | $line->log_warning("The \$@ shell variable should only be used in double quotes."); | | 4481 | $line->log_warning("The \$@ shell variable should only be used in double quotes."); |
4469 | | | 4482 | |
4470 | } elsif ($rest =~ s/^\$\$\?//) { | | 4483 | } elsif ($rest =~ s/^\$\$\?//) { |
4471 | $line->log_warning("The \$? shell variable is often not available in \"set -e\" mode."); | | 4484 | $line->log_warning("The \$? shell variable is often not available in \"set -e\" mode."); |