sstephenson / bats

Bash Automated Testing System
MIT License
7.13k stars 517 forks source link

SC2126 not always correct #183

Closed Nachtfeuer closed 8 years ago

Nachtfeuer commented 8 years ago

I do a lot of bash scripting - currently - for a ci/cd pipeline for one project but I'm probably not as deep in bash scripting like you, however ... following problem:

PROMPT="$(basename "$0") :: "

result=$(docker ps -a | grep DOES_NOT_EXIST | wc -l)
error_code=$?
echo "${PROMPT}result=${result}, error_code=${error_code}"

result=$(docker ps -a | grep -c DOES_NOT_EXIST)
error_code=$?
echo "${PROMPT}result=${result}, error_code=${error_code}"

The output of this script code is following

foo :: result=0, error_code=0
foo :: result=0, error_code=1

As you see ... the second variant with grep only fails. Obviously the count mechanism does work fine only when you have at least one entry. From this the "wc -l" variant works better except you can tell me how to solve the mentioned problem.

ztombol commented 8 years ago

Are you sure you've opened this issue on the right repository?

If yes, please see the followings and clarify the issue.

Nachtfeuer commented 8 years ago

I'm sorry. Was intended for shellcheck. Just close please.

Am 29.09.2016 16:45 schrieb "Zoltán Tömböl" notifications@github.com:

Are you sure you've opened this issue on the right repository?

If yes, please use common sense and clarify the issue.

  • Clearly specify what the issue is. What are you trying to do? What is the outcome you got and what is that you expected? People can't help you if they don't know what you want.
  • Give your issue a descriptive name. Otherwise people who may be able to help you and people who have the same issue won't find it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sstephenson/bats/issues/183#issuecomment-250487615, or mute the thread https://github.com/notifications/unsubscribe-auth/AKzoGyIhxlkWeL4o9EVUFp1rUUMQJprwks5qu88YgaJpZM4KJ5Xc .

ztombol commented 8 years ago

@Nachtfeuer no worries. I'm not the maintainer, so I can't close it. But you can.

Nachtfeuer commented 8 years ago

Accidentally wrong project. Will close it.