Skip to main content
Descriptive title. Clarified and shortened content.
Source Link

Weirdness at cmdline Why is bash not storing commands that start with spaces?

If I perform a sequence of cmdscommands like:

$ ls
$ grep abc file.txt

and then use the up arrow key to get the previous cmdone, the terminal will show the last cmd (which is the grep here)

BUT,But if I do something like this:

$ ls
$   grep abc file.txt

where the grep is prepended with multiplepreceded by spaces, the last cmd would bepressing up gives ls, and not grep.

Can someone shed some light whyWhy is this?

Weirdness at cmdline

If I perform a sequence of cmds like:

$ ls
$ grep abc file.txt

and then use the up arrow key to get the previous cmd, the terminal will show the last cmd (which is grep here)

BUT, if I do something like:

$ ls
$   grep abc file.txt

where the grep is prepended with multiple spaces, the last cmd would be ls, and not grep.

Can someone shed some light why?

Why is bash not storing commands that start with spaces?

If I perform a sequence of commands like:

$ ls
$ grep abc file.txt

and then use the up arrow key to get the previous one, the terminal will show the last cmd (which is the grep here)

But if I do something like this:

$ ls
$   grep abc file.txt

where grep is preceded by spaces, pressing up gives ls, not grep.

Why is this?

Source Link
sandyp
  • 1.2k
  • 2
  • 8
  • 11

Weirdness at cmdline

If I perform a sequence of cmds like:

$ ls
$ grep abc file.txt

and then use the up arrow key to get the previous cmd, the terminal will show the last cmd (which is grep here)

BUT, if I do something like:

$ ls
$   grep abc file.txt

where the grep is prepended with multiple spaces, the last cmd would be ls, and not grep.

Can someone shed some light why?