Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type null character in terminal

Is there a way to type the null character in the terminal?

I would like to do something like:

this is a sentence (null) test123
like image 297
functionalCode Avatar asked Sep 27 '11 16:09

functionalCode


People also ask

How do you type a null character on a Mac?

You can do this with the Unicode Hex Input method (enable it in System Preferences -> Language & Text pane -> Input Sources tab, then select it from the menu item) by holding Option and typing "0000".

How do you represent a null character?

Typically, a null character is represented by a "space" or empty data set in applications such as a word processing database and is used for filling empty spaces and padding. In programming languages/context, a null character is represented by the escape sequence \0, and it marks the end of a character string.

What is ASCII null character?

The ASCII null is represented as 0x00, and zero is represented as 0x30. The ASCII NUL character is used to denote the end of the string in C or C++. When programmer used '0' (character 0) it is treated as 0x30. This is a hexadecimal number.

WHAT IS null character with example?

In databases and spreadsheets, a null character can also be used as padding. An example of a null character is when a software developer declares a variable without specifying a value, or sets it equal to nothing.


3 Answers

In Linux, any special character can be literally inserted on the terminal by pressing Ctrl+v followed by the actual symbol. null is usually ^@ where ^ stands for Ctrl and @ for whatever combination on your keyboard layout that produces @.

So on my keyboard I do: Ctrl+v followed by Ctrl+Shift+@ and I get a ^@ symbol with a distinguished background color. This means it's a special character and not just ^ and @ typed in.

Edit: Several years later and a few input variations implemented by different terminals using keyboard layouts that require pressing Shift to access @.

  • Ctrl+v followed by Ctrl+Shift+@
  • Ctrl+v followed by Shift+@ without releasing Ctrl.
  • Ctrl+Shift+v followed by @ without releasing Ctrl+Shift.
  • Ctrl+Shift release Shift and re-press Shift keeping both Ctrl+Shift pressed followed by v and finally @. Seen in some terminals that implement a special input on Ctrl+Shift.
like image 186
unode Avatar answered Oct 11 '22 03:10

unode


$ echo -e "this is a sentence \0 test123"
this is a sentence  test123

The null here ^^ IS NOT visible

$ echo -e "this is a sentence \0 test123" | cat --show-nonprinting
this is a sentence ^@ test123

But it IS here ^^

But maybe you did not want this for a script?

like image 45
Oskar N. Avatar answered Oct 11 '22 02:10

Oskar N.


Apparently you can type this character with ^@ on some character sets. This wikipedia article on the null character may be helpful.

like image 7
tjarratt Avatar answered Oct 11 '22 01:10

tjarratt