3 # Test t0000..t9999.sh for non portable shell scripts
4 # This script can be called with one or more filenames as parameters
17 print "$ARGV:$.: error: $msg: $_\n";
21 # glean names of shell functions
23 open(my $f, '<', $i) or die "$0: $i: $!\n";
25 $func{$1} = 1 if /^\s*(\w+)\s*\(\)\s*{\s*$/;
32 # stitch together incomplete lines (those ending with "\")
38 /\bsed\s+-i/ and err
'sed -i is not portable';
39 /\becho\s+-[neE]/ and err
'echo with option is not portable (use printf)';
40 /^\s*declare\s+/ and err
'arrays/declare not portable';
41 /^\s*[^#]\s*which\s/ and err
'which is not portable (use type)';
42 /\btest\s+[^=]*==/ and err
'"test a == b" is not portable (use =)';
43 /\bwc -l.*"\s*=/ and err
'`"$(wc -l)"` is not portable (use test_line_count)';
44 /\bhead\s+-c\b/ and err
'head -c is not portable (use test_copy_bytes BYTES <file >out)';
45 /(?:\$\(seq|^\s*seq\b)/ and err
'seq is not portable (use test_seq)';
46 /\bgrep\b.*--file\b/ and err
'grep --file FILE is not portable (use grep -f FILE)';
47 /\bexport\s+[A-Za-z0-9_]*=/ and err
'"export FOO=bar" is not portable (use FOO=bar && export FOO)';
48 /^\s*([A-Z0-9_]+=(\w+|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
49 err
'"FOO=bar shell_func" assignment extends beyond "shell_func"';
50 # this resets our $. for each file