akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.33k stars 77 forks source link

Exit status 1 when using pipe and grep #430

Closed ibahnasy closed 3 months ago

ibahnasy commented 3 months ago

ble version: 0.4.0-devel4+adf9ab8 Bash version: 5.2.15(1)-release (x86_64-pc-linux-gnu)

ble.sh exists with status 1 when running a command with pipe and grep:

# lsmod | grep nvidia
[ble: exit 1]
akinomyoga commented 3 months ago

Thanks for the report, but this is the expected behavior.

ibahnasy commented 3 months ago

This is the expected behavior as it's a known bug and will be fixed or this is normal and will last like that?

Because it's really important to use pipes and grep for system administration, otherwise I have to remove ble.sh.

akinomyoga commented 3 months ago

It's not specific to ble.sh. In the plain Bash and also in any other shells, the exit status in this case is 1. This is required by the POSIX standard.

ibahnasy commented 3 months ago

Oh I see, I just was confused when it printed out the status instead of not printing anything by default, thanks.

akinomyoga commented 3 months ago

The exit status of a pipe line is the exit status of the last command in the pipe line. In this case, it is the exit status of grep. Then, the exit status of grep becomes 1 if there is no matching.

Quoted from POSIX XCU 4 grep:

EXIT STATUS The following exit values shall be returned:

  • 0 One or more lines were selected.
  • 1 No lines were selected.
  • -1 An error occurred.
akinomyoga commented 3 months ago

Oh I see, I just was confused when it printed out the status instead of not printing anything by default, thanks.

Ah, yes. Maybe I've confused you, but ble.sh prints the exit status of the previous user command when it is not 0. If you want to prevent ble.sh from printing any exit status, you can disable the feature by the following setting (as described in README 2.2):

# ~/.blerc

bleopt exec_errexit_mark=