LoginSignup
1
0

More than 1 year has passed since last update.

echo コマンドで改行を有効にするのは -e オプション

Posted at

echo で改行が反映されない

echo コマンドに何も指定しないと \n は改行コードとして反映されず、そのまま出力されてしまう。

echo "First line.\nSecond line."
First line.\nSecond line.

echo で改行を有効化する

echo -e "First line.\nSecond line."
First line.
Second line.

-e オプションでバックスラッシュエスケープの解釈を有効にすることができる。

ヘルプ

man -P cat echo | egrep '\-e|\\'
       -e     enable interpretation of backslash escapes
       If -e is in effect, the following sequences are recognized:
       \\     backslash
       \a     alert (BEL)
       \b     backspace
       \c     produce no further output
       \e     escape
       \f     form feed
       \n     new line
       \r     carriage return
       \t     horizontal tab
       \v     vertical tab
       \0NNN  byte with octal value NNN (1 to 3 digits)
       \xHH   byte with hexadecimal value HH (1 to 2 digits)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0