diff options
author | Philip Prindeville <philipp@redfish-solutions.com> | 2023-09-24 11:52:19 -0600 |
---|---|---|
committer | Paul Spooren <mail@aparcar.org> | 2023-10-23 19:18:04 +0200 |
commit | 1998027d7cbb9d8f3986964bbdae070296bdce56 (patch) | |
tree | b15e53ccdd831f7fe46637acdc4a9b2cb3d399ae /package/base-files/files/lib/functions.sh | |
parent | b23c2ec8312545b3bf20d02872c86ed7ed9f8f13 (diff) | |
download | openwrt-1998027d7cbb9d8f3986964bbdae070296bdce56.tar.gz openwrt-1998027d7cbb9d8f3986964bbdae070296bdce56.tar.bz2 openwrt-1998027d7cbb9d8f3986964bbdae070296bdce56.zip |
base-files: functions.sh: Add prepend() homologue to append()
Sometimes it's useful to be able to prepend to a variable as
well, such as when dealing with domain names, e.g.
prepend fdqn "$subdomain" "."
will result in:
fqdn="$subdomain.$fqdn"
Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Diffstat (limited to 'package/base-files/files/lib/functions.sh')
-rw-r--r-- | package/base-files/files/lib/functions.sh | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index bbdecbbc47..d9628dbb7a 100644 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -40,6 +40,14 @@ append() { eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" } +prepend() { + local var="$1" + local value="$2" + local sep="${3:- }" + + eval "export ${NO_EXPORT:+-n} -- \"$var=\${$value:+\${$value}\$sep}\$var\"" +} + list_contains() { local var="$1" local str="$2" |