My question "sh: 1: !: not found" in GitHub Actions is getting downvoted, but I can't think why. It's dispiriting, and it would be nice to get some idea of what I've written that's considered unhelpful.
1 Answer
I think your question looks okay. I wouldn't have downvoted it, personally. That said, I can immediately see some minor warts that might have (not outright unreasonably, but perhaps a bit harshly) led someone to downvote:
Your final sentence betrays a fundamental confusion about the nature of the
sh
command.sh
does not consistently refer to some kind of single standard shell implementation across different Unix systems, and this has apparently been the case since the 1970s. The norm nowadays is that thesh
executable on your path is actually a symlink to some shell binary with a meaningful identifying name, e.g.zsh
on macOS ordash
on Ubuntu. In general, all you can expect is that when you runsh
you will get some kind of shell compatible with the POSIX standard for whatsh
has to supply, but some such shells (most notably Bash) have significant additional functionality beyond what POSIX mandates they have, making it very easy to accidentally write a non-portable shell script that works on your machine but is broken on systems wheresh
is some different shell. (Relevant reading: What are syntax differences between bash and dash?.)At a glance, I'd guess that this confusion is probably not relevant to your actual question, but having included the error in the question perhaps invites answers to address it, arguably broadening the scope of the question drastically and making it two questions in one.
Your code demonstrating the problem includes a very slightly long and complicated chain of Git commands (
(git diff --quiet HEAD^ VERSION && git diff --quiet HEAD^ src/**)
) that adds a tiny bit of irrelevant complexity and makes the code block horizontally scroll. Presumably these could just be replaced with a shorter command (maybe justfalse
, or just one side of the&&
) while preserving the essence of the question.(This feels like a fairly petty nitpick to me given that it's far more common than it should be for askers to dump, like, 100 lines of code to demonstrate an issue that could be illustrated in 5, and to the extent that there is even a real problem with non-minimal code here it is orders of magnitude less bad.)
There are some obvious investigatory steps that you give no hint of having taken (and certainly don't mention the findings of in the question), such as seeing if you still get the error about
!
not being found if you change your command to justsh -c "! git diff --quiet HEAD^ src/VERSION"
. With only a tiny bit of extra tinkering you could've nailed down more precisely what circumstances cause the error to happen, leaving the focus of the question on explaining why this is the case and how to correctly avoid; instead that work of tinkering around and figuring out precisely which aspects of the provided code are essential to producing the error is left to people trying to answer.As I understand GitHub Actions, the commands get executed on a "runner" VM, but there's no information about what OS your runners are using, nor in particular what the default shell pointed to by
sh
is on them. If this information is relevant to reproducing the error (and maybe it isn't, I dunno!) then it's an important omission. (As is often the case, it's hard for me to tell just by looking if this is a real problem with the question or not; only somebody who knows the answer or has at least investigated a bit can tell.) I'd err on the side of including such information when first asking a question, knowing you can always edit it out later, once you've got an answer, if it turns out in hindsight to have been irrelevant noise.
Would I downvote over any of these warts, or even over the sum total of them? No; I think this fairly low level of wartiness is basically par for the course when even a fairly conscientious user asks a question that they genuinely don't know the answer to yet and are confused about, and answerers can and should just tweak the question as needed to tidy things up. But maybe some other users are harsher than me.
(And perhaps there are more profound problems I'm failing to see, that someone who fully sees and understands what the answer is can see. If so I hope they spell them out.)
-
1Indeed. When a questioner is so confused about the area where they are having problems that they can't articulate a well-formed question, I think our duty is to help them resolve their confusion, not simply to downvote or reject the question. Commented Nov 15 at 9:31
-
3@MichaelKay Hmm. I actually don't agree with that framing; I do think that if an asker is so confused that they have failed to ask a well-formed, comprehensible question, then it is virtually guaranteed to be non-useful and deserving of being downvoted, closed, and deleted. (Helping resolve the confusions in the comments is supererogatory.) I'm inclined to defend this question precisely because it is well-formed despite some confusion; we can understand precisely what the asker's situation is and what he is asking despite the tangential misunderstanding he lets on in his final sentence. Commented Nov 15 at 9:42
-
1
|
.sh
or GitHub Actions. (I originally tagged itsh
but someone removed that tag.) Are devops questions not welcome on SO? If not, I'd expect close votes with a view to migrating it, rather than downvotes. And also if not, what's the CI/CD collective about?!
. What is its specific purpose in the command? Is it, in fact, intended to be part of the shell syntax, or what?!
is for history expansion; but I'm not sure if vanillash
supports it, it is disabled by default in scripts and I can't see why you'd want to use it here, nor how you intend to specify which command from history. All of which is not trying to answer the question, but to explain why the question is confusing.)sh: 1: !: not found
means "some part of the Github Actions implementation can't findsh
"? No; it means thatsh
can't find!
. It's important to have some experience with shell scripting before trying to use it within a special environment like this one or embed shell code in another file format like YAML.!
you need an expression, not a command. Alternatively: it's not a builtin syntax element, but rather an argument to theif
shell builtin. (&&
is similarly imperative, not logical.) If that's the source of the misunderstanding then there is a valid underlying question that's purely about shell script. I don't know if there's a canonical for that.|
character fix things? Without a full explanation of why the code behaves differently with vs without the extra|
, the fix seems like voodoo. (I think I have correctly inferred the full explanation, thanks in part to Benjamin W's comment below the answer, but I expect a solid majority of readers would not understand even with the help of Benjamin's comment.)