Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/check-non-portable-shell.pl # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / check-non-portable-shell.pl` 58 lines ยท 1897 bytes Raw Blame History 1 #!/usr/bin/perl 2 3 # Test t0000..t9999.sh for non portable shell scripts 4 # This script can be called with one or more filenames as parameters 5 6 use strict; 7 use warnings; 8 9 my $exit_code=0; 10 my %func; 11 12 sub err { 13 my $msg = shift; 14 s/^\s+//; 15 s/\s+$//; 16 s/\s+/ /g; 17 print "$ARGV:$.: error: $msg: $_\n"; 18 $exit_code = 1; 19 } 20 21 # glean names of shell functions 22 for my $i (@ARGV) { 23 open(my $f, '<', $i) or die "$0: $i: $!\n"; 24 while (<$f>) { 25 $func{$1} = 1 if /^\s*(\w+)\s*\(\)\s*{\s*$/; 26 } 27 close $f; 28 } 29 30 my $line = ''; 31 while (<>) { 32 chomp; 33 $line .= $_; 34 # stitch together incomplete lines (those ending with "\") 35 next if $line =~ s/\\$//; 36 37 $_ = $line; 38 /\bcp\s+-a/ and err 'cp -a is not portable'; 39 /\bsed\s+-[^Eefn]\s+/ and err 'sed option not portable (use only -E, -n, -e, -f)'; 40 /\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)'; 41 /^\s*declare\s+/ and err 'arrays/declare not portable'; 42 /^\s*[^#]\s*which\s/ and err 'which is not portable (use type)'; 43 /\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)'; 44 /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)'; 45 /\bhead\s+-c\b/ and err 'head -c is not portable (use test_copy_bytes BYTES out)'; 46 /(?:\$\(seq|^\s*seq\b)/ and err 'seq is not portable (use test_seq)'; 47 /\bgrep\b.*--file\b/ and err 'grep --file FILE is not portable (use grep -f FILE)'; 48 /\b[ef]grep\b/ and err 'egrep/fgrep obsolescent (use grep -E/-F)'; 49 /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)'; 50 /\blocal\s+[A-Za-z0-9_]*=\$([A-Za-z0-9_{]|[(][^(])/ and 51 err q(quote "$val" in 'local var=$val'); 52 /\b([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and !/test_env.+=/ and exists($func{$4}) and 53 err '"FOO=bar shell_func" is not portable (use test_env FOO=bar shell_func)'; 54 $line = ''; 55 # this resets our $. for each file 56 close ARGV if eof; 57 } 58 exit $exit_code;