Sh - Backslash Escape Characters (Whitespace, Tabs, Ends, End of Line, Newline) - Non-printing characters

Bash Liste Des Attaques Ovh

About

Text - Non-printing Character (Tabulation, New Line, ) in bash

Format

Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:

  • \a: alert (bell)
  • \b backspace
  • \e an escape character
  • \f form feed
  • \r carriage return
  • \t horizontal tab
  • \v vertical tab
  • \\: backslash
  • \' single quote
  • \nnn the eight-bit character whose value is the octal value nnn (one to three digits)
  • \xHH: the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
  • \cx a control-x character

The expanded result is single-quoted, as if the dollar sign had not been present.

Management

Init

var variable=$'TextWithTab\tInBetween'

Concat

variable="First"$'\n'
variable=$variable"Second"$'\n'
echo "$variable"
First
Second


Echo

The echo command must have its parameter between parenthesis to show the newlines in a variable

# Variable
TEST=$`Hello\nNico`
echo "$TEST"
# or Text
echo -e "Hello\nNico"
Hello
Nico

!!!! Bad/wrong !!!!

# Bad
echo $TEST
Hello Nico

Show

Cat

To see the backslash character, you need to use the cat command.

echo $'Hello\tWorld\vHello \nHello ' | cat -vte

where:

  • for $'Hello\tWorld\vHello \nHello '
  • the cat options:
    • v: show non-printing
    • T: show tabs
    • E: show ends

Output:

Hello^IWorld^KHello $
Hello $

where:

  • ^I represents a horizontal tab
  • ^K represents a vertical tab
  • $ represents an end-of-line

Sed

Shell Data Processing - Sed (Stream editor)

echo $'\t' | sed 's/ /·/g;s/\t/→/g;s/\r/§/g;s/$/¶/g'





Discover More
Bash Liste Des Attaques Ovh
Bash - Character

Character section of bash. See also:
Bash Liste Des Attaques Ovh
Bash - IFS (Field Separator)

The field separator is a set of character that defines one or more field separator that separates (delimit) field (word) in a string. DELIM It's defined in the IFS variable parameters statement...
Bash Liste Des Attaques Ovh
Bash - Read (Builtin Command) that capture a line

Read is a bash builtin command and read: by default one line or a number of characters (by option) from: the standard input, or from the file descriptor fd supplied as an argument to the...
Data System Architecture
Character - Whitespace

White-space characters is a set of characters that contains: spaces, tabs, and line breaks They are part of the non printing characters. They may be a difference between the class: ...
Bash Liste Des Attaques Ovh
Sh - String Variable

String Variable, see also character string in bash. When calling a function, quote the variable otherwise bash will not see the string as atomic but as an array Sh with Bash “” The...



Share this page:
Follow us:
Task Runner