27

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.

25
  • 2
    It doesn't look too bad on the surface, I guess if you were being really picky then it doesn't show research effort but bit that would seem a bit harsh to me, maybe the deleted comments gave more insight?
    – Sayse
    Commented Nov 13 at 12:11
  • 14
    dev/ops questions are tricky on a site originally designed for purely programming problems, Stack Overflow does not understand yet how to judge them. They all look off-topic. If you look at the questions under the github actions tag, you won't find a whole lot of voting love there. Or answers for that matter.
    – Gimby
    Commented Nov 13 at 13:29
  • 10
    Maybe it would be a question better suited for a site for DevOps, DevOps?
    – Thom A
    Commented Nov 13 at 13:47
  • 9
    Maybe some people think it's a typo question and not particularly helpful for future readers? It looks like the issue is just the missing |. Commented Nov 13 at 14:25
  • 2
    Tbh not much really. The only thing you could change is making the title a full on question like 'Why does only github actions throw "sh: 1: !: not found"?' But thats more of stylistic preference I have noticed on SO. I have the impression that once a question has a negative score it is far more likely to recive more downvotes. This question of mine which I edited (even asking the meta chat for advice) and it keeps getting downvotes on occasion.
    – A-Tech
    Commented Nov 13 at 15:23
  • 3
    @ThomA I see your reasoning. It would be a difficult call as an asker because I didn't know if the problem was with sh or GitHub Actions. (I originally tagged it sh 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?
    – joel
    Commented Nov 13 at 15:28
  • 20
    "And also if not, what's the CI/CD collective about?" A (very) poor choice by Stack Overflow. If only the Stack Overflow community had mentioned there was a site dedicated to CI/CD within the larger community... Oh wait... They did.
    – Thom A
    Commented Nov 13 at 15:30
  • 1
    " the later sections gives me... only in GitHub Actions. It runs fine on my computer." It's not clear to me what you mean by "runs fine". The code you show is a YAML file that happens to have some shell code embedded within it. How exactly do you "run" that? With Docker or something? Or do you mean that the shell command in isolation works locally? It also isn't clear to me what you expect the command to do. The error is complaining about the !. What is its specific purpose in the command? Is it, in fact, intended to be part of the shell syntax, or what? Commented Nov 13 at 17:58
  • 1
    (as far as I'm aware, ! is for history expansion; but I'm not sure if vanilla sh 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.) Commented Nov 13 at 18:03
  • 7
    "I don't understand how that could be since I very explicitly mention the shell." - it's not clear why you think this matters. Did you read the error message and conclude that sh: 1: !: not found means "some part of the Github Actions implementation can't find sh"? No; it means that sh 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. Commented Nov 13 at 18:07
  • 1
    "It would be a difficult call as an asker because I didn't know if the problem was with <technology X> or <technology Y>. ". This is inherently a problem with the question on Stack Overflow. It is your responsibility before asking to figure that out first. Commented Nov 13 at 18:10
  • 7
    "software tools commonly used by programmers" are explicitly on topic here (stackoverflow.com/help/on-topic) ... doesn't that include sh and GitHub Actions in the context of the question? Commented Nov 13 at 18:22
  • 1
    @StayOnTarget in the context, yes. Writing a YAML file like this is "programming" the GitHub Actions system - it isn't a generic tech support question - and the embedded shell command also appears to involve programming logic (i.e., it isn't something that a non-programmer would use to operate the computer). Commented Nov 13 at 19:36
  • 1
    To negate with ! you need an expression, not a command. Alternatively: it's not a builtin syntax element, but rather an argument to the if 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. Commented Nov 13 at 22:33
  • 1
    The question looks at least okay to me at first glance, but the answer seems rather mediocre. Why does adding the extra | 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.)
    – Mark Amery
    Commented Nov 14 at 11:04

1 Answer 1

9

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 the sh executable on your path is actually a symlink to some shell binary with a meaningful identifying name, e.g. zsh on macOS or dash on Ubuntu. In general, all you can expect is that when you run sh you will get some kind of shell compatible with the POSIX standard for what sh 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 where sh 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 just false, 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 just sh -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.)

3
  • 1
    Indeed. 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.
    – Mark Amery
    Commented Nov 15 at 9:42
  • 1
    Low Level Wartiness you say. God I like the sound of that.
    – Gimby
    Commented Nov 15 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .