Lemmy: Bestiverse
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
RSS BotMB to Hacker NewsEnglish · 29 days ago

Debugging Bash Like a Sire

blog.brujordet.no

external-link
message-square
0
fedilink
4
external-link

Debugging Bash Like a Sire

blog.brujordet.no

RSS BotMB to Hacker NewsEnglish · 29 days ago
message-square
0
fedilink
Debugging Bash like a Sire
blog.brujordet.no
external-link
Many engineers have a strained relationship with Bash. I love it though, but I’m very aware of it’s limitations when it comes to error handling and data structures (or lack thereof). As a result of these limitations I often see Bash scripts written very defensively that define something like: set -euxo pipefail These are bash builtin options that do more or less sensible things. e: Exit immediately when a non-zero exit status is encountered u: Undefined variables throws an error and exits the script x: Print every evaluation. o pipefail: Here we make sure that any error in a pipe of commands will fail the entire pipe instead just carrying on to the next command in the pipe. All of these are quite useful, thought I tend to skip the -u flag as bash scripts often interact with global variables that are set outside my scripts. The -x flag is extremely noisy so it’s most often used manually when debugging. And to be honest, I don’t really use -o pipefail either. I guess this is a good place for a few words of caution when it comes to this approach. Feel free to dig into this reddit comment, but to summarize, the behavior of these flags aren’t consistent across Bash versions and they can break your scripts in unexpected ways.

Comments

alert-triangle
You must log in or register to comment.

Hacker News

hackernews

Subscribe from Remote Instance

You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !hackernews@lemmy.bestiver.se
lock
Community locked: only moderators can create posts. You can still comment on posts.

Posts from the RSS Feed of HackerNews.

The feed sometimes contains ads and posts that have been removed by the mod team at HN.

Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 370 users / day
  • 1.56K users / week
  • 4.21K users / month
  • 9.58K users / 6 months
  • 2 local subscribers
  • 2.37K subscribers
  • 28.9K Posts
  • 11.5K Comments
  • Modlog
  • mods:
  • patrick
  • RSS Bot
  • BE: 0.19.5
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org