Failed to convert bash script to zsh script

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 run Zsh with 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}

The other commands in the first code seem correct for Zsh.

How can you convert the code to Zsh?

+5
source share
1 answer

You save the text as a single line / object, and not as a "replacement". You can either save the line correctly:

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

Or do word splitting on your variable:

TODO_OPTIONS="--timeout --summary"
....
devtodo ${=TODO_OPTIONS}
+4
source

All Articles