How do I use the -ne flag for echo in a shell script?

12,474

Solution 1

That would be the difference between echo in /bin/sh vs. your interactive shell. I suggest using printf instead, and see The UNIX and the echo.

Solution 2

The problem is that your shell recognizes different escape codes than your /bin/sh.

/bin/sh probably doesn't recognize \e as the escape character. Try \033 instead.

You can also replace \a by the equivalent code\007 and see if that works.

Share:
12,474

Related videos on Youtube

robin smith
Author by

robin smith

Updated on September 18, 2022

Comments

  • robin smith
    robin smith over 1 year

    I'm trying to create a shell script to take an argument and use it to name a terminal tab. So if the script's name is tabnm, tabnm "test" should rename the current tab "test"

    This is my code:

    #!/bin/sh
    echo -ne "\e]1;$1\a"
    

    but when i run it I get this output:

    robin@icarus $ sh tabnm.sh test
    -ne \e]1;test

    If I just run echo -ne "\e]1;Test\a" straight in the shell, the tab is renamed.

    • Kirk
      Kirk almost 13 years
      Is /bin/sh a symlink to /bin/bash on your system?