diff options
author | Eli Schwartz <eschwartz93@gmail.com> | 2023-12-13 00:01:39 -0500 |
---|---|---|
committer | Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org> | 2024-01-22 14:12:18 +0100 |
commit | 2a5ff80264825e21adb5ff107a3d01237b86f559 (patch) | |
tree | 1887d7f6a5d814fe96d86dea60302847b98f64e4 /bin | |
parent | cf02724e5101801d0a316f6b099c14c4fce77d9a (diff) |
use portable "command -v" to detect installed programs, part 4
The "which" utility is not guaranteed to be installed either, and if it
is, its behavior is not portable either. This means that when various
programs are installed, the `which` check will report a fatal error
because the which tool did not exist and the shell returned a nonzero
status when attempting to fork+exec. If it did exist, it might not be an
implementation of `which` that returns nonzero when commands do not
exist.
The general scripting suggestion is to use the "command -v" shell
builtin; this is required to exist in all POSIX 2008 compliant shells,
and is thus guaranteed to work everywhere.
For some in-depth discussions on the topic, see:
- https://mywiki.wooledge.org/BashFAQ/081
- https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then/85250#85250
Examples of open-source shells likely to be installed as /bin/sh on
Linux, which implement the 15-year-old standard: ash, bash, busybox,
dash, ksh, mksh and zsh.
This commit updates a couple build scripts to not rely on fixed paths
calculated upfront. Checking the location of a tool with cmd=$(which
foo) just to run it as `$cmd` is pointless. It's exactly equivalent to
run it as `foo`, but less error-prone and easier to read.
For one of the scripts, it also simplifies checking for their existence.
Personally, I am skeptical it even makes sense to check at all. POSIX
mandates they exist, and it's exceedingly unlikely they will not be
installed. However, unlike the shell interpreter itself, we don't *know*
they are installed, so leave the existing checks in but simplified.
Change-Id: I4703c1165eb3a5aeb45fbab18df3222e8f5f9551
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160665
Tested-by: Jenkins
Tested-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/removetooltip_markups.sh | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/bin/removetooltip_markups.sh b/bin/removetooltip_markups.sh index 5699fce99263..056c9753e510 100755 --- a/bin/removetooltip_markups.sh +++ b/bin/removetooltip_markups.sh @@ -10,13 +10,11 @@ # Run the script in the core directory to remove all tooltip_markup # properties from the .ui files -SED_BIN=`which sed` -CUT_BIN=`which cut` LOG_FILE="modified-$(date +%s).log" removeTooltipMarkup() { - LINE=$(grep -n "<property name=\"tooltip_markup\"" $1 | $CUT_BIN -f 1 -d ':') + LINE=$(grep -n "<property name=\"tooltip_markup\"" $1 | cut -f 1 -d ':') TEXT=$(grep "<property name=\"tooltip_markup\"" $1) grep -v "<property name=\"tooltip_markup\"" $1 > temp && mv temp $1 echo "removed $TEXT from $1 at line $LINE" >> $LOG_FILE @@ -24,8 +22,8 @@ removeTooltipMarkup() changeTooltipMarkup() { - LINE=$(grep -n "<property name=\"tooltip_markup\"" $1 | $CUT_BIN -f 1 -d ':') - $SED_BIN "s/tooltip_markup/tooltip_text/g" $i > temp && mv temp $1 + LINE=$(grep -n "<property name=\"tooltip_markup\"" $1 | cut -f 1 -d ':') + sed "s/tooltip_markup/tooltip_text/g" $i > temp && mv temp $1 echo "renamed tooltip_markup from $1 at line $LINE" >> $LOG_FILE } |