tags:

views:

391

answers:

1

I need to change the following Bash code to Zsh

TODO_OPTIONS="--timeout --summary"
         cd ()
         {   
             builtin cd "$@"
             RV=$?
             [ $RV = 0 -a -r .todo ] && devtodo ${TODO_OPTIONS}
             return $RV 
         }   

         pushd ()
         {   
             builtin pushd "$@"
             RV=$?
             [ $RV = 0 -a -r .todo ] && devtodo ${TODO_OPTIONS}
             return $RV 
         }   

         popd ()
         {   
             builtin popd "$@"
             RV=$?   
             [ $RV = 0 -a -r .todo ] && devtodo ${TODO_OPTIONS}
             return $RV 
         }   

         # Run todo initially upon login
         devtodo ${TODO_OPTIONS}

I get the following error when I start Zsh with the code

todo: error, unknown argument '--timeout --summary', try --help

I feel that Zsh cannot understand the following line

[ $RV = 0 -a -r .todo ] && devtodo ${TODO_OPTIONS}

Other commands in the first code seems to be right for Zsh.

How can you convert the code to Zsh?

+2  A: 

You're saving the text as one string/object, instead of as a simple "thing to substitute". You can either save the string properly:

TODO_OPTIONS=(--timeout --summary)
....
devtodo ${TODO_OPTIONS}

Or run word splitting on your variable:

TODO_OPTIONS="--timeout --summary"
....
devtodo ${=TODO_OPTIONS}
viraptor
@viraptor: Thank you for your answer!
Masi
The first version of your codes works. :)
Masi