#!/bin/bash vs #!/bin/sh
I hate when people use #!/bin/bash in their shell scripts!
Today, at omnitel.unix – a lithuanian newsgroup, there was a question “massive nslookups”. A guy said that he has a text file with IP addresses one per line, and asked how to lookup them all.
A few hours later, a guy who’s nickname is ‘bash’ (heh…) replied to the message… i was mad after reading it.
The reply was a bash script:
#!/bin/bash
LIST1=ip #ip list file
LIST2=host #file, which will contain resolved hosts
while read IP
do
host $IP | cut -d’ ‘ -f5 | sed s/.$// >> $LIST2
done < $LIST1
I replied with a little modified version – changed ‘host’ command with cuts and sed’s to one ‘dig +short’ command.
Also, i’ve made a note that this script does not have any bash specific stuff, so /bin/sh would be more appropriate
“What’s the difference? /bin/sh will run faster ?
)”
No, and yes. No as it’s not the important part here. And yes – it will run faster. But, as i said, that’s not important.
By using /bin/sh your little script will work on all ( fix me if i’m wrong) unix-like operating systems, and not only lunix’es which have /bin/bash as a default shell and link /bin/sh to /bin/bash.
Changing two characters (from ‘bash’ to ‘sh’) on such a simple script changes the list of systems it works from ‘linux’ to ‘any unix-like system’.
That guy didn’t get it even after saying that. ‘Most people use Linux. FreeBSD is used by a few people like you.’.
I promised not to reply to that thread anymore. Talking with that kind of people makes me sick.
Oh, and as i promised not to reply to that thread anymore, i couldn’t fix my answer. My initial fix missed a ‘-x’ in dig command + i offered not to output to a file, it can be done by redirecting the output of the script itself, and not dig/host command.
Final ‘code’ i’d offer is:
#!/bin/sh
if [ "x" = x"$1" ]; then
echo “usage: $0 <file_with_ips>”
exit 1
fi
for IP in `cat $1`; do
dig +short -x $IP
done
Heh, those kids can be really obnoxious. I remember a discussion about distros, when some dude started bloating, that in Gentoo, he compiled everything himself using great Gentoo’s community tutorials, that he is the master and runs MySQL, Apache, Zope, Samba, NFS, CUPS, PHP, distCC and bazillion other services on his P4 machine, and his computer runs 0,0001% faster than RHEL using i486 binaries (he said “who needs i486 when you have 64bits?”).
When I asked him – whether he really uses or needs all the crap he is runnig, he replied: “You don,t understand Gentoo. I’ve been here for 3 months and know it all.”. So yeah – ricers are Gentoo-specific kind of assholes
But you know, it’s really sad, that OSS, which is not only about technology, but also about being open-minded, free and nice, attracts assholes who think they can push their crap and wage humanity’s classical “who’s dick is bigger” war using distro names for “size” references.
Someone should write a script to filter them out. A /bin/sh script
And by the way – could you please give me link to that thread? I’d like to flame a little
Sorry for the delay, i didn’t find any good web-based nntp client. Anyway, first match on google found one, the link to this thread is here:
http://www.news.mazgas.com/article/news.omnitel.net/omnitel.unix/62450
Sadly, but usability of this web-based nntp really sucks
Yeah, well. This “bash” dude is a moron. There is only hope someone’ll bash him
I fully agree with you