benrady / shinatra

A simple web server in 5 lines of bash
811 stars 81 forks source link

Use printf to print equal signs multiple times #10

Closed nir0s closed 4 years ago

benrady commented 7 years ago

On which platforms is printf installed by default?

nir0s commented 7 years ago

Um.. printf is a part of bash since 4.1.7 I believe.

nir0s commented 7 years ago

And btw, since performance is very important here, printf is faster :)

benrady commented 7 years ago

Looks like it's also part of the coreutils package in Homebrew.


brady$ which printf
/usr/local/opt/coreutils/libexec/gnubin/printf
Artoria2e5 commented 7 years ago

Looks like it's also part of the coreutils package in Homebrew.

Seriously, stop using which. It only knows about commands in your PATH and ignores those builtin ones.

$ type printf
printf is a shell builtin

$ type cat
cat is hashed (/usr/bin/cat)

$ type if
if is a shell keyword

$ type type # of course..
type is a shell builtin

$ command -v printf
printf

$ command -v cat
/usr/bin/cat

$ type command
command is a shell builtin

Um.. printf is a part of bash since 4.1.7 I believe.

Also in bash 3.2.(??) found in OS X I think. man printf links to a "shell builtins" manpage as far as I can recall.

j8r commented 7 years ago

Personally I'm against this PR because this will remove the POSIX compliance of this little script. However we can replace the echo -en by printf. Finally we should replace #!/usr/bin/env bash by #!/usr/bin/env sh