dylanaraps / pure-sh-bible

📖 A collection of pure POSIX sh alternatives to external processes.
MIT License
6.45k stars 281 forks source link

Add note about is_int portability. #14

Open periish opened 4 years ago

spiralofhope commented 4 years ago

Unless I misunderstood:

Reproduced in zsh 5.7.1-1 under a Debian 10.1.0-amd64 install, (though updated recently).

Running that script with a header of #!/usr/bin/env sh and using the script ./script.sh 1 produces no output.

neeasade commented 4 years ago

I was able to reproduce.

@spiralofhope is you sh not symlinked to zsh? Here is how I reproduced:

$ echo 'printf %d "$1" >/dev/null 2>&1' >test.sh
$ sh ./test.sh not_number
! # <-- correct exit code
$ ln -s $(which zsh) ./sh
$ ./sh ./test.sh "not_number"
$ # exit code of 0
spiralofhope commented 4 years ago

You noted an exit code of !, did you mean 1 ?

My sh is symlinked to dash 0.5.10.2-5

echo 'printf %d "$1" >/dev/null 2>&1' >test.sh
# Actually dash:
sh ./test.sh not_number ; echo $?
1
ln -s $(which zsh) ./sh
./sh ./test.sh "not_number"; echo $?
0

At no point in my tests does the printf display anything.

neeasade commented 4 years ago

oh yeah my bad - the error I was trying to highlight was the exit code, I don't print anything either, of course.