Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: first adventures



On 10/29/2014 09:07 PM, Bart Schaefer wrote:
On Oct 29,  4:31pm, Ray Andrews wrote:
I believe you have done it, sir:

   #!/usr/bin/zsh


   typeset -g TLC
   TRAPDEBUG()
   {

      # This works perfectly to print directly to screen:
      #(( $#functrace == 1 )) && print -u2 "$ZSH_DEBUG_CMD"

      # Top Level Command capture:
      (( $#functrace == 1 )) && TLC="${ZSH_DEBUG_CMD}"
   }

   test()
   {
      # We only want the arguments so chop off the command itself:
      chop_cmd=${TLC/$0/}
      echo
      print -ru2 "My unexpanded arguments were: $chop_cmd"
      print -u2 "\n...and my arguments broken to an array:\n"

      array=("${=chop_cmd}")

      print -ru2 "two:   $array[2]"
      print -ru2 "three: $array[3]"
      print -ru2 "four:  $array[4]"
      print -ru2 "five:  $array[5]"
      print -ru2 "six:   $array[6]"
   }

It is proof against glob or variable expansion, it swallows redirection, and it doesn't mind compound command lines, however it does expand bangchar, as wanted:

   $ test ls $PWD; test ls g* > /dev/null; test l ,H $PWD/test; test 'I
   wandered \n lonely as a cloud'; test "that \n floats on high"

   My unexpanded arguments were:  ls $PWD

   ...and my arguments broken to an array:

   two:   ls
   three: $PWD
   four:
   five:
   six:
   My unexpanded arguments were:  ls g* > /dev/null

   ...and my arguments broken to an array:

   two:   ls
   three: g*
   four:  >
   five:  /dev/null
   six:

   My unexpanded arguments were:  l ,H $PWD/test

   ...and my arguments broken to an array:

   two:   l
   three: ,H
   four:  $PWD/test
   five:
   six:

   My unexpanded arguments were:  'I wandered \n lonely as a cloud'

   ...and my arguments broken to an array:

   two:   'I
   three: wandered
   four:  \n
   five:  lonely
   six:   as

   My unexpanded arguments were:  "that \n floats on high"

   ...and my arguments broken to an array:

   two:   "that
   three: \n
   four:  floats
   five:  on
   six:   high"


... I think I can't even quibble about the quoted strings not being treated as single arguments because I can't have it both ways--the whole exercise is to have zero processing.

And I don't even need to rape the src.







Messages sorted by: Reverse Date, Date, Thread, Author