Don't execute lsb_release more than once #69

Closed
opened 2019-03-20 18:56:00 +01:00 by jlecour · 3 comments
Owner

Each time a Debian version is checked, lsb_release is executed. It accounts for almost half a second.

Each time a Debian version is checked, `lsb_release` is executed. It accounts for almost half a second.
jlecour self-assigned this 2019-03-20 18:56:00 +01:00
Author
Owner

I've found a way, but there is a weird bug that I can't see :

#!/bin/sh

DEBIAN_RELEASE=""

debian_release() {
    if [ -z "${DEBIAN_RELEASE}" ]; then
        DEBIAN_RELEASE=$(lsb_release -c -s)
    fi

    printf "%s" "${DEBIAN_RELEASE}"
}

printf "Debian release (from fun) : %s\n" "$(debian_release)"
printf "Debian release (from var) : %s\n" "${DEBIAN_RELEASE}"

It should print

Debian release (from fun) : stretch
Debian release (from var) : stretch

but it prints this :

Debian release (from fun) : stretch
Debian release (from var) :

What am I missing ???

I've found a way, but there is a weird bug that I can't see : ``` #!/bin/sh DEBIAN_RELEASE="" debian_release() { if [ -z "${DEBIAN_RELEASE}" ]; then DEBIAN_RELEASE=$(lsb_release -c -s) fi printf "%s" "${DEBIAN_RELEASE}" } printf "Debian release (from fun) : %s\n" "$(debian_release)" printf "Debian release (from var) : %s\n" "${DEBIAN_RELEASE}" ``` It should print ``` Debian release (from fun) : stretch Debian release (from var) : stretch ``` but it prints this : ``` Debian release (from fun) : stretch Debian release (from var) : ``` What am I missing ???
jlecour changed title from Don't execute `lsb-release` more than once to Don't execute `lsb_release` more than once 2019-03-20 19:46:07 +01:00
Owner

IMHO when you exec $(debian_release) it opens a sub-shell and it doesn't modify your real DEBIAN_RELEASE variable.

IMHO when you exec $(debian_release) it opens a sub-shell and it doesn't modify your real DEBIAN_RELEASE variable.
Author
Owner

Exactly, thanks!

The shell language is no fun here.
I didn't find a way to call a function inside an interpolation, without changing the scope of variables.

Here is the workaround I've found : f732577b9a503316452d6a56686c944722bfc20e

Exactly, thanks! The shell language is no fun here. I didn't find a way to call a function inside an interpolation, without changing the scope of variables. Here is the workaround I've found : f732577b9a503316452d6a56686c944722bfc20e
benpro added a new dependency 2019-03-21 10:36:35 +01:00
benpro added the
enhancement
label 2019-03-21 10:54:08 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference: evolix/evocheck#69
No description provided.