Re: [dev] [sw] Suckless web-framework

From: Paul Malherbe <paul_AT_tartan.co.za>
Date: Mon, 05 Apr 2010 00:32:58 +0200
On 05/04/10 00:02, Uriel wrote:
I just want to say thanks for reminding me how absolutely hideous sh
scripts are and to stay away from them.

I honestly can't see why anyone would willfully write anything in sh
anymore (of course, plain sh is better than using bash, ksh or any
other horrible extensions of an already awful thing).

uriel


On Sun, Apr 4, 2010 at 7:03 PM,  <node@lavabit.com> wrote:
  
# grep thinks the second argument is a file
        
BL="^index.md$ ^images$"  # Black list
          
  BL="^index.md$\|^images$" # Black list
        
Wrong, take a look at this line:
BL=`echo ${BL} | sed -e "s/\( \+\|^\)/ -e /g"`
      
Yes, -e allows you to do this. However, in the original code you had
    
BL="^index.md$ ^images$"  # Black list
      
and later...
    
      for i in `ls ${SITE}/${DIR} | grep -v ${BL}`; do
      
I know the blacklist ($BL) was meant as an example, but if you run this
code you'll see that grep errors out because it thinks `^images$' is a
file.

If you really want people to use space as a delimiter, then either do:

 for i in BL; do
       tmp="$tmp -e $i"
 done
 BL=$tmp
 grep -q $BL

or:

 set -- $BL
 IFS='|'
 BL=$*
 grep -Eq "$BL" ...

Both are pretty stupid.

    
# echo | blah is becoming rampant; let's not ignore it this time
        
QUERY=`echo ${REQUEST_URI} | sed -e "s,.*${BIN}/*\(.*\),\1,"`
          
  QUERY=`sed "s,.*$BIN/*\(.*\),\1," <<-!
     $REQUEST_URI
     !
        
So, it is better to use 3 loc for this?
      
Sadly, POSIX shell sucks. In bash, perl and powershell you could get
away with a less verbose herestring:

 grep pattern <<< str

    
# Why heredoc instead of subshell?
# Compare: time for i in `seq 1 1000`; do echo str | grep pattern
        
/dev/null; done
          
# ...with: time for i in `seq 1 1000`; do grep pattern >/dev/null <<-!
#                                    str
#                                    !
             # heredocs can also contain subshells... you save one
             # from `cmd | cmd`
        
           DIR=`dirname ${QUERY} | sed -e "s,/*$,,"`>
#                                  done
          
I see, this is a more interesting argument for using heredocs. But,
just a question (because I don't really know) is heredocs as standard as
a plain "echo blah | cmd" ?
      
heredocs are defined by POSIX, if that's what you mean by standard


Semi unrelated question: why are so many people at suckless using ` `
instead of $( ) ? I've seen it here, dmenu_path, surf's config.h... etc.

$( ) only fails in very, very old shells... think original bourne





    

  
Hi

Again I totally agree with Uriel, rather use a good scripting language like python ;-)

Regards

Paul


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean. Received on Sun Apr 04 2010 - 22:32:58 UTC

This archive was generated by hypermail 2.2.0 : Sun Apr 04 2010 - 23:12:03 UTC