4 ms·
Bash. I'm obsessed - so much so that I'll solve more complex problems taking 3x time rather than falling back to Python. And then there's bash one-liners, they'
by Fizzadar 11y ago
Bash. I'm obsessed - so much so that I'll solve more complex problems taking 3x time rather than falling back to Python. And then there's bash one-liners, they're the best!
- m0nty 11y agoI too love bash. It's always there. It has no dependencies. It works.
- paulddraper 11y agoIt has a dependency on the bash runtime. And coreutils. And often moreutils, or various others.
- lmedinas 11y agoOften with better performance than Python or Perl
- cms07 11y agoI don't think that's true with Perl at least, unless something has changed dramatically very recently.
- hrez 11y agoIf you use it to glue/pipe bunch of tools written in C it can easily be faster.
- paulddraper 11y agoThat's one recommend approach towards Python. E.g. numpy. The other approach is pure Python and then using PyPy's JIT.
- lmedinas 11y agoWhich often is what you do in Bash with grep, cp, mv, find etc...
- antod 11y agoThe only times I've ever had a bash script run faster than Perl or Python is when it has handed most of the work off to another utility (eg written in C). The actual bash processing bits seem much slower than Perl or Python.
- bsg75 11y agoIsn't most heavy work in bash done by piping data to C based utilities, with bash just being the "glue"?
- LeoPanthera 11y agoI've written a bidirectional filesystem synchronization tool, and a content management system, in (nearly) pure bash. I keep expecting the performance to be terrible but it's surprisingly efficient.
- i336_ 11y agoObfuscated oneliners are where it gets really, really fun though. I love making these, because they can be edited and iterated directly from the terminal prompt, and you can just paste them from the clipboard to see if you like them and want to keep them. For example, the URL this oneliner spits out is actually real. The technique works almost nowhere now thanks to HTTPS (it's one of my poorest oneliners), but it's hilarious to show people who don't know about networking. $ echo http://google.com/trends | (E=echo\ ;S=sed\ ;read a;x=($($E "$a"|$S's,^\([^:]\+://\)*\([^/]\+\)/\(.*\)$,\1 \2 \3,'));$E"${x[0]}$(i=32;o=0;for x in $(ping -c1 "${x[1]}"|$S's/[^(]\+(//;s/).*//;;s/\./ /g;q');do((o+=(x*(2**(i-=8)))));done;$E$o)/$(for((i=0;i<${#x[2]};i++));do printf "%%%x" "'${x[2]:i:1}";done)") http://3627736174/%74%72%65%6e%64%73 If you use VT100's alternate character sets you might like this character map which shows all the character mappings at once (man console_codes for the idea behind B0UK) (((r=255/((${COLUMNS:-$(tput cols)}-16)/18)));C="\e[38;5";Z="\e[0m";A="\e(";for((i=-1;i<r;i++));do X=;for((j=0;c=20,(v=j*r+i),v<256;j++));do((v>r-(\!(i+1)+1)))&&X="$X$C;177m |";((\!(i+1)))&&X="$X$Z 0UKB ddd/ooo/hh"||{(((v>32&&v<127)||v>160))&&printf -v c %x $v;printf -v X "$X $C;160m${A}0\x$c${A}U\x$c${A}K\x$c${A}B\x$c $C;120m%3d$Z/$C;214m%03o$Z/$C;33m%02x" $v $v $v;X=${X//\%/%%};} done;printf "$X\n";done) Then there's this one I won't tell you about, which #bash suggested I put in the channel bot (!! wow) when I showed them... run it in a 256-color terminal. :P E=echo\ ;P=printf\ ;M=$'\e[0m';a(){ $P"\e[38;5;2${z}5;48;5;${1}m %4d $M" $1;};Z=$E$M;for i in 16 93 160;do ((r=(n=\!n)*2-1));for((x=0;x<6;x++,i+=r)) do for((j=0;L=(i+(R=(j/6?17-j:j))*6),z=(R%6>1?3:5),j<12;j++))do a $L;done;$E;done;done;z=5;for i in {0..23};do a $[i+232];((i==11))&&$Z;done;for i in {0..15};do ((i==8||\!i))&&$P'\n%*s' 12;a $i;done;$E