-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement read -n, and a placeholder for -r.
Addresses issue #26.
- Loading branch information
Andy Chu
committed
Sep 6, 2017
1 parent
42e9dec
commit 4e3e9a7
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters