Type null character in terminal

2020-03-01 08:12发布

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

4条回答
来,给爷笑一个
2楼-- · 2020-03-01 08:29

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

查看更多
劳资没心,怎么记你
3楼-- · 2020-03-01 08:47
$ 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?

查看更多
▲ chillily
4楼-- · 2020-03-01 08:48

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.
查看更多
我想做一个坏孩纸
5楼-- · 2020-03-01 08:50

As with the abort command (Ctrl-C), in most terminals just hit Ctrl-@ (with the use of Shift on my keyboard).

查看更多
登录 后发表回答