Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Jul 2014 22:00:37 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r269351 - head/usr.sbin/bsdconfig/share
Message-ID:  <201407312200.s6VM0bKt034692@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Thu Jul 31 22:00:36 2014
New Revision: 269351
URL: http://svnweb.freebsd.org/changeset/base/269351

Log:
  Define a setvar() function for platforms using a shell unlike FreeBSD's
  sh(1) for `/bin/sh' (e.g., bash(1) which lacks a setvar definition).
  This is to improve portability to other Operating Systems (e.g., Linux).

Modified:
  head/usr.sbin/bsdconfig/share/common.subr

Modified: head/usr.sbin/bsdconfig/share/common.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/common.subr	Thu Jul 31 20:55:05 2014	(r269350)
+++ head/usr.sbin/bsdconfig/share/common.subr	Thu Jul 31 22:00:36 2014	(r269351)
@@ -220,6 +220,32 @@ f_have()
 	f_quietly type "$@"
 }
 
+# setvar $var_to_set [$value]
+#
+# Implement setvar for shells such as unlike FreeBSD sh(1).
+#
+if ! f_have setvar; then
+setvar()
+{
+	[ $# -gt 0 ] || return $SUCCESS
+	local __setvar_var_to_set="$1" __setvar_right="$2" __setvar_left=
+	case $# in
+	1) unset "$__setvar_var_to_set"
+	   return $? ;;
+	2) : fall through ;;
+	*) f_err "setvar: too many arguments\n"
+	   return $FAILURE
+	esac
+	while case "$__setvar_r" in *\'*) : ;; *) false ; esac
+	do
+		__setvar_left="$__setvar_left${__setvar_right%%\'*}'\\''"
+		__setvar_right="${__setvar_right#*\'}"
+	done
+	__setvar_left="$__setvar_left${__setvar_right#*\'}"
+	eval "$__setvar_var_to_set='$__setvar_left'"
+}
+fi
+
 # f_which $anything [$var_to_set]
 #
 # A fast built-in replacement for syntaxes such as foo=$( which bar ). In a



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407312200.s6VM0bKt034692>