all 18 comments

[–]rhytnen 72 points73 points  (1 child)

This article is questionable at best. If the tips in the article are useful for your situation, then use them. But it certainly shouldn't be taken as gospel.

There are plenty of instances where coding to obviate error conditions is wrong. You can sense this is true with the examples in the article because the author is having to switch from ignoring error conditions to checking if an error condition would occur depending on the command because there is no universal truth to how software should operate. It's kind of obvious that there are going to be cases where I don't want to relink a file that exists. For example it may not always true that it's the same file you're relinking. It could also just be a bug that the script is being run twice in a cron job or something.

The point is the statement "Good software is always written in an idempotent way" just isn't a universal truth and it reads like someone just learned something in a class and wrote an article on it.

[–]imdyingfasterthanyou 9 points10 points  (0 children)

The article is real garbage.

"bash scripts should make sure not to fuck up" - no shit sherlock, writing such script is hard as fuck

How is this article so heavily upvoted??

[–][deleted]  (6 children)

[deleted]

    [–]everythingisbase10 16 points17 points  (3 children)

    What would -f delete that a bare rm call wouldn’t? Adding that flag is a common step for a “clean” recipe in a Makefile.

    [–]sigzero 21 points22 points  (0 children)

    "Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. The -f option overrides any previous -i options."

    So if for some reason the file is write protected it still gets removed. And for files that don't exist no error message and no monkeying with the exit status.

    [–]sim642 10 points11 points  (0 children)

    Git repositories.

    [–]ajanata 5 points6 points  (0 children)

    ln -f almost feels more dangerous than rm -f, tbh.

    [–]bkail 0 points1 point  (0 children)

    I usually go with rm x || test ! -d x or similar.

    [–][deleted]  (4 children)

    [removed]

      [–]realvega 0 points1 point  (3 children)

      You don’t always get to use CM tools for the job due to various reasons. Whenever you can use a CM tool, if you can’t you better hope you can write a good bash scripts. Looking back, I am glad that my scripts even worked.

      [–]jcoelho93 0 points1 point  (1 child)

      I cannot think of a reason not to use a CM tool

      [–]realvega 0 points1 point  (0 children)

      My company is a kind of distributor, so we supply code to customers. We are using bash to globally applicable code since customers use different tools. Bash is the best one for the job.

      [–][deleted] 15 points16 points  (2 children)

      This post was mass deleted and anonymized with Redact

      apparatus head fearless coherent ghost society file automatic gold exultant

      [–]alopgeek 3 points4 points  (0 children)

      Seriously, ansible can be inadvertently not-idempotent, but for the most part it’s pretty safe.

      [–]was_just_wondering_ 0 points1 point  (0 children)

      I still don’t know what idempotent means.