• 0 Posts
  • 53 Comments
Joined 1 year ago
cake
Cake day: July 1st, 2023

help-circle












  • This works fine for me:

    function foo() {
      bar[0]="hello"
      bar[1]="world"
      return 1
    }
    if ! foo; then
      echo "${bar[@]}"
    fi
    

    https://onlinegdb.com/xPIFP110w


    Are you getting messed up by the way bash handles exit statuses? An exit status of 0 indicates a success and a non-zero exit status indicates a failure (which allows for the different exit statuses to indicate different errors).

    So if my_func; then something; fi will only run something when my_func returns 0. In your case, you’re using ! to do the opposite so it only runs when your function returns a non-zero status.

    This can be quite surprising if you’re expecting the behavior found in other languages like python or C++ where 0 represents false and 1 represents true.



  • It’s contextual. If it’s used in a phone number, it’s a pound sign. If it’s placed before a number, it’s a number sign. If it’s placed before a tag, it’s a hash/hashmark/hashtag.

    No one would pronounce “#foo” as “pound foo” any more than they’d call a #2 pencil a “pound two pencil”. Because “pound” is clearly not the right name in either context.

    Americans have been comfortable using different names for the symbol in different contexts since long before hashtags even existed. So when websites started using them and referred to them as “hashtags”, that was fine. It was a new context so it could use whichever name it wanted. (Well, “octothorpe-tag” is probably far too unwieldy to catch on.)

    Of course if we’re talking about the symbol without a specific context, then we have to pick one of the names. For most Americans, that “default” name is probably still “pound”. Twenty years ago I’d definitely say that, but even then it wasn’t ubiquitous. It wasn’t uncommon to hear it referred to as a hash. And it seems like the use of “pound” has declined and the use of hash has increased as people now spend more time online and less time dialing phone numbers. There’s also a generational divide with older people more likely to say “pound” and younger people more likely to say “hash”.