Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set 4 space tab in bash

Tags:

bash

space

It look like set tabstop=4 in VIM, but I don't know how to set it in bash

for example:

echo -e "1234567890\t321\n1\t2\n123\t1" 

current output:

1234567890      321 1       2 123     1 

I want output like this:

1234567890  321 1   2 123 1 

It can be shown in anywhere, just like cat somefile or php -r 'echo "\t123";'

How can I set tab width in bash?

like image 643
Zheng Kai Avatar asked May 28 '12 09:05

Zheng Kai


People also ask

How do I set tab to 4 spaces in Linux?

The shiftwidth parameter controls your indentation size; if you want four space indents, use :set shiftwidth=4 , or the abbreviation :set sw=4 .

How do I give a tab space in bash?

tab-insert (M-TAB) Insert a tab character.

How do I set tab space in Linux?

Use spaces for indentingThe first line enables expandtab option in Vim. This option makes sure that spaces are used for indenting lines, even when you press the 'Tab' key. The second option tabstop takes a numerical value. Let's say I typed set tabstop=2, this will insert 2 spaces for a line indent.

How many spaces is a tab in bash?

By default, it's 8 which corresponds to the default tab stop in terminals.


1 Answers

That's not a property of your shell (or php or cat). It's your terminal that manages the output.

Use the tabs command to change the behavior:

$ tabs 4  $ echo -e "a\tb"       a   b $ tabs 12  $ echo -e "a\tb"  a           b 

(tabs is specified in POSIX, and output above is "faked": it's still a tab character between the two letters.)

like image 58
Mat Avatar answered Sep 18 '22 14:09

Mat