What are idempotent scripts? (#note)

Even though I studied computer science, some terms and concepts won’t stick in my head. I have to look up "idempotence" or "idempotent scripts" repeatedly.
Wikipedia defines the term "Idempotence" as fo…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Even though I studied computer science, some terms and concepts won't stick in my head. I have to look up "idempotence" or "idempotent scripts" repeatedly.

Wikipedia defines the term "Idempotence" as follows:

Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application.

The concept is not hard to understand, though. A script is idempotent when its repeated execution always leads to the same result. Whether it's the first or thirtieth run, it should "just work". This approach seems logical, but not every script follows it.

Consider a script that creates configuration files and directories:

  • Does the script still work when it runs a second time, or does it fail because specific files exist already?
  • Is the script appending the same lines of code to config files, or does it check if these lines are already included?
  • Are there other side effects that could influence the result of the script?

Fatih Arslan's post How to write idempotent Bash scripts is an excellent explainer on the topic, and it includes many Bash examples on how to reach idempotence. 👏


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2021-12-08T23:00:00+00:00) What are idempotent scripts? (#note). Retrieved from https://www.scien.cx/2021/12/08/what-are-idempotent-scripts-note/

MLA
" » What are idempotent scripts? (#note)." Stefan Judis | Sciencx - Wednesday December 8, 2021, https://www.scien.cx/2021/12/08/what-are-idempotent-scripts-note/
HARVARD
Stefan Judis | Sciencx Wednesday December 8, 2021 » What are idempotent scripts? (#note)., viewed ,<https://www.scien.cx/2021/12/08/what-are-idempotent-scripts-note/>
VANCOUVER
Stefan Judis | Sciencx - » What are idempotent scripts? (#note). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/08/what-are-idempotent-scripts-note/
CHICAGO
" » What are idempotent scripts? (#note)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2021/12/08/what-are-idempotent-scripts-note/
IEEE
" » What are idempotent scripts? (#note)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2021/12/08/what-are-idempotent-scripts-note/. [Accessed: ]
rf:citation
» What are idempotent scripts? (#note) | Stefan Judis | Sciencx | https://www.scien.cx/2021/12/08/what-are-idempotent-scripts-note/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.