[Home] Zsh logo

undual

Zsh Wizard

Download undual Return to Examples
  1. #!/bin/zsh
  2. #
  3. # undual - remove a name from the dual list
  4. #
  5. # [2000-09-29]
  6. # Version 3.1.6 of zsh automates this functionality with
  7. # typeset -T. I'll leave this function here for historical purposes.
  8. #
  9. # Usage:
  10. # undual [name] . . .
  11. #
  12. # where
  13. # name is the name of a shell variable to remove from the
  14. # dual list. See dual for more. You can't remove
  15. # dual itself from the dual list, which is kind of
  16. # good.
  17. #
  18. # assumes unsetopt shwordsplit
  19. # Might require a POSIX sed, on account of the
  20. # \(:\|$\) (colon or end of line) construct. In awk it becomes
  21. # (:|$) which is much easier to read. I use sed because it's a little
  22. # less memory-hungry.
  23. #
  24. # each name . . .
  25. for name
  26. do
  27. # get uppercase version
  28. upper=${(U)name}
  29. # if there is no dual list, quit now.
  30. if [[ -z "$dual" || -z "$DUAL" ]]
  31. then
  32. break
  33. fi
  34. # remove the item from the dual list - with dual!
  35. dual DUAL=$(echo $DUAL | sed "s/:$upper\(:\|$\)/\1/")
  36. # and remap the dual array to lower case.
  37. dual=(${(L)dual})
  38. done