Skip to content

Commit e2b5740

Browse files
committed
Remove unnecessary use of eval from install script
The "template" installation script hosted in this repository contains a `checkLatestVersion()` function which is used to determine the latest version of the project when the user does not specify a version to install. The version number is required by the caller, but shell functions do not support returning such content. As a workaround, the script author set up a system where the caller passed an arbitrary variable name to the function. The function then sets a global variable of that name with the release name. So it resembles a "pass by reference" approach, but isn't. This was done using the `eval` builtin. This tool must be used with caution and best practices is to avoid it unless absolutely necessary. The system used by the script has some value for a reusable function. However, in this case the function is only intended for internal use by the script, and is called only once. So the unintuitive nature of this system and potential for bugs don't bring any benefits when compared with the much more straightforward approach of simply using a fixed name for the global variable used to store the release name.
1 parent 1e6183c commit e2b5740

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: other/installation-script/install.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ initDownloadTool() {
7070
echo "Using $DOWNLOAD_TOOL as download tool"
7171
}
7272

73+
# checkLatestVersion() sets the CHECKLATESTVERSION_TAG variable to the latest version
7374
checkLatestVersion() {
7475
# Use the GitHub releases webpage to find the latest version for this project
7576
# so we don't get rate-limited.
@@ -84,7 +85,6 @@ checkLatestVersion() {
8485
echo "Cannot determine latest tag."
8586
exit 1
8687
fi
87-
eval "$1='$CHECKLATESTVERSION_TAG'"
8888
}
8989

9090
getFile() {
@@ -101,7 +101,8 @@ getFile() {
101101

102102
downloadFile() {
103103
if [ -z "$1" ]; then
104-
checkLatestVersion TAG
104+
checkLatestVersion
105+
TAG="$CHECKLATESTVERSION_TAG"
105106
else
106107
TAG=$1
107108
fi

0 commit comments

Comments
 (0)