Explain Shell
151–160 of 179 posts
Re: Explain Shell
#152Very well done. Now I just wish this was a shell program! user@server:~$ explain iptables -A INPUT -i eth0 -s ip-to-block -j DROP
Re: Explain Shell
#153There is no perfect solution -- in the ideal world, everyone would use safe healthy programming languages, and nobody would be addicted to shell scripting.
But in the real world, many people still choose to use shell scripting as a quick and easy short term solution to their problems.
Like the unhealthy temptation to use regexps for parsing html, shell scripting just causes more problems, which snowball out of control until you have the dire situation we're in today, with a whole generation of urban hipsters who learned cargo-cult cut-n-paste shell scripting by typing "more ./configure".
So it's much better to treat shell scripting as a health problem rather than a criminal problem.
My only suggestion is that you should sponsor links to "recovery programs," where people can learn to solve their problems with safe healthy programming languages instead of shell scripts. For the popular rube-goldbergesque shell incantations, you could show how to accomplish the same thing more comprehensibly in Python, Ruby, JavaScript, Lisp, Forth, Mathematica, Quartz Composer, etc. ;)
Re: Explain Shell
#154Very well done. Now I just wish this was a shell program! user@server:~$ explain iptables -A INPUT -i eth0 -s ip-to-block -j DROP
#!/usr/bin/env python import sys import urllib import webbrowser url = "http://explainshell.com/explain?cmd=" + urllib.quote(' '.join(sys.argv[1:])) webbrowser.open_new(url) (webrowser.open_new doesn't seem to be always working for me, not sure why, I've never used it before)
One suggestion though: If there are no command line parameters, then read a line from stdin, so you don't have to play the game of trying to properly escape all of your punctuation in the command line to get it into sys.argv[1:] without any corruption, and can just copy and paste it into stdin.
Hmm, that raises the question of what should happen if you pipe an entire shell script into it, like "./configure"? That might be considered a denial of service attack on explainshell.com.
Re: Explain Shell
#155echo `uptime|grep days|sed 's/.up \([0-9]\) day.*/\1\/10+/'; cat \ /proc/cpuinfo|grep '^cpu MHz'|awk '{print $4"/30 +";}';free|grep \ '^Mem'|awk '{print $3"/1024/3+"}'; df -P -k -x nfs | grep -v \ 1k | awk '{if ($1 ~ "/dev/(scsi|sd|md)"){ s+= $2} s+= $2;} END \ {print s/1024/50"/15+70";}'`|bc|sed 's/\(.$\)/.\1cm/
Re: Explain Shell
#156Earlier quoted context omitted.
Or you may shorten your command ps -C someScript.sh -o pid= | xargs -I % /bin/kill -TERM -- -% avoiding two pipes is also 1 femtosecond faster, and as an added bonus HN doesn't trigger the dreaded code scrollbars too!
This is the two best arguments I have ever seen comparing two piece of code! You totally convinced me.
pkill ^someScript.sh$ --signal TERM
Either way pgrep is a nice command to learn about.