>> # 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




Reply via email to