linux - Odd issue with OR operator in zsh

07
2014-07
  • Hamy

    I'm seeing an odd issue with CentOS 6.4, zsh 4.3.10 (x86_64-redhat-linux-gnu).

    This is running two regular expressions on the same string. Neither expression passes the if conditional, but when I OR them together

    $ if [[ "foo" =~ "^\s*$" ]]; then; echo "Test"; fi
    $ if [[ "foo" =~ "^\.+$" ]]; then; echo "Test"; fi
    $ if [[ "foo" =~ "^\.+$" || "foo" =~ "^\s*$" ]]; then; echo "OR test"; fi
    OR test
    

    This only happens on CentOS as far as I can tell, I get expected behavior with zsh 5.0.2 (x86_64-apple-darwin13.0) and zsh 5.0.2 (x86_64-pc-linux-gnu)

  • Answers
  • Josip Medved

    Last if should be slightly different if or is desired. Try:

    if [[ "foo" =~ "^\.+$" ]] || [[ "foo" =~ "^\s*$" ]]; then; echo "OR test"; fi
    

  • Related Question

    linux - problem with zsh interactive shell
  • Jack

    When I use zsh in interactive mode, I get some glitches. This mainly happens when the command spills over onto a new line and I use backspace, with backspace leaving behind some glitches on the screen and moving the cursor to an odd position.

    It happens in a VT, in xterm and urxvt, although it is most noticeable with my chosen terminal, urxvt.

    When I use zsh as a login shell, it does not happen at all.

    What could be causing this?


  • Related Answers
  • Dennis Williamson

    It would help if you showed what your PROMPT variable is set to when it's not working, but it's likely that you have escape sequences that are being counted in the width of the prompt. You can fix this by editing the value so that those sequences are surrounded by %{ ... %}.

  • DevSolar

    The shell and your terminal program have to agree on:

    • the size, capabilities and behaviour of the window;

    • the number of characters displayed on it; these numbers could start to differ e.g. when one side assumes Unicode while the other assumes Latin encoding, or when a backspace isn't handled correctly.

    Your termcap / terminfo settings, and the configuration of your terminal program, must be consistent, or you get exactly the behaviour you describe.

    Sadly, I'm not as proficient with these settings as I would like to be, and can't really pinpoint what you should change where. (Have to leave room for others to earn upvotes, huh? ;-) )