help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Use readonly wherever possible?


From: D630
Subject: Use readonly wherever possible?
Date: Wed, 06 May 2020 10:44:08 +0200
User-agent: Posteo Webmail

Recently, I had to review one of my team members shell code. She is a Java developer, and used to declare variables with the final keyword. So in shell she was constanly using the readonly attribute like:

foo() {
        local -r bar=$1
        local -r lich=$2
        echo "$((bar * lich))"
}

I think that's unusual code in the shell-code universum. My first reflex was to say "No, don't do that", but I hesitate with my answer, because I have no idea what happens exactly in bash when a variable is declared readonly. So is there any advantage in using readonly wherever possible?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]