Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

hr(){printf '=%.0s' $(seq $COLUMNS)}


Here is a copy-n-paste to your bash prompt:

    function hr { printf '=%.0s' $(seq $COLUMNS); }


What language is that?


bash shell, although some whitespace is missing:

    hr() { printf '=%.0s' $(seq $COLUMNS); }
printf is a bash builtin


Actually printf is a POSIX standard shell utility. Bash happens to implement it as a builtin, but there's also a conforming copy in GNU coreutils (and presumably busybox, but I didn't check). And the syntax above is standard Bourne shell, not specifically bash.

Actually of the constructs in that, the only non-portable one is the seq tool, which (I think) is unique to coreutils.


I don't know if its still the case, but OSX used to not ship with seq. Instead, you had to use jot.


OSX 10.9 ships a 'seq'. This particular version was written in 2005 by the NetBSD project, and its provenance is NetBSD 3.0 -> FreeBSD 9.0 -> OSX.

Fwiw, it isn't a GNUism, though GNU's version was the first widely distributed one. A 'seq' appears in some old Research UNIX editions, and also in Plan9, but not in commercial AT&T Unix or in BSD. Instead 'jot' is the traditional BSD utility. Not sure if commercial AT&T Unix (and descendants) had anything similar.


zsh


yup, using zsh, I tend to forgot that Bash needs spaces inside brackets. This is a good reminder though:

:(){ :|:& };:

Edit: don't run this, it's a forkbomb


And double check the formatting before you tattoo it on your arm.


nice and simple! added to my .zshrc :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: