On Fri, Jan 07, 2011 at 05:07:47AM -0600, David Champion wrote:
> * On 07 Jan 2011, Yue Wu wrote:
> > On Fri, Jan 07, 2011 at 03:40:12PM +0800, du yang wrote:
> > >
> > > if [ $(date -d "$(date '+%Y-%m-%d')" "+%s") -gt $epoch ]; then
> > >      echo "%4C %Z %{%d.%m.%y} %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"
> > > else
> > >      echo "%4C %Z %{   %H:%M} %-15.15F (%?l?%4l&%4c?) %?H?[%H]?%s%"
> > > fi
> >
> > Must it be bash script? No bash here, it fails the test with sh...
> 
> This is a POSIX sh script, not Bourne, which is why it fails for you.
> Specifically, $(command) is a POSIX construction that is not supported
> by conventional Bourne shells.  You can fix it by replacing this:
> 
> if [ $(date -d "$(date '+%Y-%m-%d')" "+%s") -gt $epoch ]; then
> 
> with this:
> 
> now=`date '+%Y-%m-%d'`
> if [ `date -d "$now" "+%s"` -gt $epoch ]; then
> 
> However, if I'm not mistaken that command still relies on GNU extensions
> to the "date" command.  (Mixing POSIX and GNU is another common
> portability problem in the Linux era.)  Since you appear to be using
> FreeBSD you may have problems with that even after adapting the shell
> syntax.  (In fact I think it's even more confusing.  Where the -d
> option will simply fail on a pure POSIX system, I think it is actually
> a completely different option on BSD, which has its own extensions
> separate from GNU's.)
> 
> Remember that setting $index_format to a piped command means that the
> command is run once each time a message is displayed on your index.  I
> wrote the code to allow $index_format to be a piped command, and as I
> remember the result is *not* cached.  Since the command in this case is
> a shell script, it's actually going to run three commands: sh, date, and
> another date.
> 
> For these reasons -- portability and performance -- I would not use
> shell for this purpose.  I prefer Python, but Perl might be a better
> choice since it typically has a lower startup time.  Naturally for
> performance concerns, C would be the best choice.
> 

Thank you detailed explanation! I got it. I concern the performance,
and it isn't a must feature, it's just for curiosity :)

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China

Reply via email to