Shell

在不同的 shell 中使用“echo -e”轉義序列

  • December 7, 2020

我剛剛注意到,Linux 上我的 shell 中-e的命令似乎不存在該標誌。echo這只是一個混亂的設置還是“正常”?

一些程式碼作為例子:

#!/bin/sh
echo -e "\e[3;12r\e[3H"

印刷:

-e \e[3;12r\e[3H

這以前有效!我猜有些stty命令出了很大的錯誤,現在它不再起作用了。有人建議我sh的其實只是bash

因為您使用sh, not bash, then echocommand insh沒有 option -e。從sh手冊頁:

echo [-n] args...
           Print the arguments on the standard output, separated by spaces.
           Unless the -n option is present, a newline is output following the
           arguments.

它也沒有\e

       If any of the following sequences of characters is encountered
       during output, the sequence is not output.  Instead, the specified
       action is performed:

       \b      A backspace character is output.

       \c      Subsequent output is suppressed.  This is normally used at
               the end of the last argument to suppress the trailing new‐
               line that echo would otherwise output.

       \f      Output a form feed.

       \n      Output a newline character.

       \r      Output a carriage return.

       \t      Output a (horizontal) tab character.

       \v      Output a vertical tab.

       \0digits
               Output the character whose value is given by zero to three
               octal digits.  If there are zero digits, a nul character
               is output.

       \\      Output a backslash.

       All other backslash sequences elicit undefined behaviour.

引用自:https://unix.stackexchange.com/questions/88307