Skip to content

Commit f3ca216

Browse files
committed
Small style/safety cleanups
1 parent d2af288 commit f3ca216

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

prerequisites/build-functions/set_or_print_url.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
# shellcheck shell=bash
12
# If -p, -D, -P, or -V specifies a package, set package_url
23
# If -U specifies a package, print the package_url and exit with normal status
34
# shellcheck disable=SC2154
45
set_or_print_url()
56
{
67
# Verify requirements
7-
[ ! -z "${arg_U}" ] && [ ! -z "${arg_D:-${arg_p:-${arg_P:-${arg_V:-${arg_B}}}}}" ] &&
8+
[[ -n "${arg_U}" && -n "${arg_D:-${arg_p:-${arg_P:-${arg_V:-${arg_B}}}}}" ]] &&
89
emergency "Please pass only one of {-B, -D, -p, -P, -U, -V} or a longer equivalent (multiple detected)."
910

1011
# Get package name from argument passed with -p, -D, -P, -V, or -U
1112
package_to_build="${arg_p:-${arg_D:-${arg_P:-${arg_U:-${arg_V:-${arg_B}}}}}}"
1213

13-
if [[ ! -z ${arg_u:-} ]]; then
14+
if [[ -n "${arg_u:-}" ]]; then
1415
# User specified a URL from which to download the package
15-
url_tail=${arg_u##*/} # set url_tail to text_after_final_slash
16-
url_head=${arg_u%%${url_tail}} # set url_head text before url_tail
16+
url_tail="${arg_u##*/}" # set url_tail to text_after_final_slash, greedy expansion needed
17+
url_head="${arg_u%${url_tail}}" # set url_head text before url_tail
1718
else
1819

1920
if [[ "${package_to_build}" == 'cmake' ]]; then
@@ -87,12 +88,12 @@ else
8788
emergency "Package ${package_name:-} not recognized. Use --l or --list-packages to list the allowable names."
8889
fi
8990

90-
fi # end if [[ ! -z $arg_u ]]; then
91+
fi # end if [[ -n "${arg_u:-}" ]]; then
9192

9293
package_url="${url_head}""${url_tail}"
9394

9495
# If a printout of the package URL was requested, then print it and exit with normal status
95-
if [[ ! -z "${arg_U:-}" ]]; then
96+
if [[ -n "${arg_U:-}" ]]; then
9697
printf "%s\n" "${package_url}"
9798
exit 0
9899
fi

0 commit comments

Comments
 (0)