Permalink
Please sign in to comment.
Browse files
Implement read -n, and a placeholder for -r.
Addresses issue #26.
- Loading branch information...
Showing
with
72 additions
and 2 deletions.
- +24 −2 core/builtin.py
- +32 −0 gold/nix.sh
- +12 −0 spec/builtins.test.sh
- +4 −0 test/gold.sh
| @@ -0,0 +1,32 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Usage: | ||
| # ./nix.sh <function name> | ||
| set -o nounset | ||
| set -o pipefail | ||
| set -o errexit | ||
| # My simpler rewrite. | ||
| isElfSimple() { | ||
| local path=$1 # double quotes never necessary on RHS | ||
| local magic | ||
| # read 4 bytes from $path, without escaping, into $magic var | ||
| read -r -n 4 magic < "$path" | ||
| # Return the exit code of [[ | ||
| [[ "$magic" =~ ELF ]] | ||
| } | ||
| isElfSimpleWithStdin() { | ||
| seq 3 > /tmp/3.txt | ||
| while read line; do | ||
| echo $line | ||
| isElfSimple /bin/true && echo YES | ||
| isElfSimple $0 || echo NO | ||
| echo | ||
| done < /tmp/3.txt | ||
| } | ||
| "$@" |
0 comments on commit
4e3e9a7