1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Copied from hard-coded-descriptors/ in oilshell/blog-code, which was copied
|
4 | # from Nix setup.sh. See issue #26.
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | # My simpler rewrite.
|
11 | isElfSimple() {
|
12 | local path=$1 # double quotes never necessary on RHS
|
13 | local magic
|
14 |
|
15 | # read 4 bytes from $path, without escaping, into $magic var
|
16 | read -r -n 4 magic < "$path"
|
17 |
|
18 | # Return the exit code of [[
|
19 | [[ "$magic" =~ ELF ]]
|
20 | }
|
21 |
|
22 | isElfSimpleWithStdin() {
|
23 | seq 3 > /tmp/3.txt
|
24 | while read line; do
|
25 | echo $line
|
26 | isElfSimple /bin/true && echo YES
|
27 | isElfSimple $0 || echo NO
|
28 | echo
|
29 | done < /tmp/3.txt
|
30 | }
|
31 |
|
32 | "$@"
|