From nobody Fri Dec 27 21:44:02 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YKfC62PPHz5jP2m; Fri, 27 Dec 2024 21:44:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YKfC61jxSz4k2Y; Fri, 27 Dec 2024 21:44:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735335842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=U86BAcYmXIhszF0qPS2dxuXVD1ucYcBdzTboL8u/fxE=; b=H77N/eY44rtfcreNywpKrRLFLWMVAm/0c6D6bHaqLzwef0aeVb+GybSA9sQunAw8TBNgEH 8/Bru6h6zcrISwztQfPneuAV9TM1JEgrjieMYE596eP93r823lfqz9jMWJQgq3KcvWFwqF t5dSrfTeudUL8RiLLFrn+zuVFTrPWImwxKKBfkJBNmW02hTaVlzLlsV2/EZxHBmf+fiWI1 ig33Apfktq+Tx01kAg6IQIbmFkWpGsXgAN1RFAT9v9Nw5uH8BQnyztMw0sxmQr2/4/w9l7 q7CHBc0kmSQGZdtD1/B5zJeqmoQtZuuo9hvW7gbQV7bD7gOpi613dmJ/HroMhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735335842; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=U86BAcYmXIhszF0qPS2dxuXVD1ucYcBdzTboL8u/fxE=; b=e5aIPC//lVDNFuXoYTLmDeudikVftR5QRIFqlYeIQyJK/1sYgYc3VBSpLCOf1vZWJXJ+aa 3qV8wg5dFBru6HStoQiHuVoKjC0ZLJfq2RvOCwpmLWtfUyDZFAmDsc7J638MaFgnR06MtE CL8aLIvKNhF+u1s6y0FdaJiBJaKRjWpo23SSjpC9/LZw7ao+uoB0qrys/VnVBwv+sIJX3y jpfKIQcE1XcYSuO8T1vnm/lzG0INoPybYvOSD6tXUzEcz2rOYd+Q7K+3hnRxJxSj4RkTNM vicaWR0HnvAoYpzsP7vEPDyzmUZOH8UMzAUkv+1lRBETodR4NyGbg/tLg8VKWA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735335842; a=rsa-sha256; cv=none; b=ItLFqELUBVesfHGt+uI41E5rWEdf4yIBJK4lPuSwR4ZOexWvm2A61UpOgPzjHsMyRC6lJv QUy0sUGONHIWkDJb4U5UaasJLtE6YTStsEMxLqHNEN7yw0rBcLFx1iGF2iVRaPExj4iG4e dmoA2yy7qfs/mPBe+qugIirHGVYzPcahRsrWErosp5xz3P6tRQ9z19W00/7DDnYU05Ng/G xJUHJEsyHPRfYk3GGUlw1dBvFWZcAQlKYEwmJl/jrWoSIe+A40WgI72KVeI541C1erqjz0 CYwEOW+XGA21Tfpp9P0AHvSKAXBp4HT7333TEP8FHhKJPbvFJFRAQZsvNq5EhA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YKfC61JstzwG1; Fri, 27 Dec 2024 21:44:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BRLi2rq062643; Fri, 27 Dec 2024 21:44:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BRLi2Jx062640; Fri, 27 Dec 2024 21:44:02 GMT (envelope-from git) Date: Fri, 27 Dec 2024 21:44:02 GMT Message-Id: <202412272144.4BRLi2Jx062640@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Joerg Wunsch Subject: git: 1330ea449802 - stable/13 - MFC: devd.conf(5): explain difference between internal and shell variables List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: joerg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1330ea449802aaf36d4e3fb8e98fcee5be1f5aeb Auto-Submitted: auto-generated The branch stable/13 has been updated by joerg: URL: https://cgit.FreeBSD.org/src/commit/?id=1330ea449802aaf36d4e3fb8e98fcee5be1f5aeb commit 1330ea449802aaf36d4e3fb8e98fcee5be1f5aeb Author: Joerg Wunsch AuthorDate: 2024-12-20 20:16:52 +0000 Commit: Joerg Wunsch CommitDate: 2024-12-27 21:42:54 +0000 MFC: devd.conf(5): explain difference between internal and shell variables devd.conf by default considers many variables as internal, possibly expanding them to an empty string. Shell variables thus need to be wrapped into braces. Reviewed by: imp, Andre Albsmeier Differential Revision: (cherry picked from commit 1fc7922f9f905b62ef9a6c03be498c282e7b382e) --- sbin/devd/devd.conf.5 | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/sbin/devd/devd.conf.5 b/sbin/devd/devd.conf.5 index 5e438ab6aeac..49d4ef84c5fa 100644 --- a/sbin/devd/devd.conf.5 +++ b/sbin/devd/devd.conf.5 @@ -38,7 +38,7 @@ .\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS .\" SOFTWARE. .\" -.Dd September 22, 2022 +.Dd December 20, 2024 .Dt DEVD.CONF 5 .Os .Sh NAME @@ -668,6 +668,26 @@ For example: // part of the previous comment. .Ed .Ss Notes on Variable Expansion +Variables are expanded by preceding them by a +.Dq $ +sign. +Any text immediately following that sign, starting with a letter, a minus sign +.Dq - , +an underscore +.Dq _ , +or an asterisk +.Dq * +is considered an internal variable, and expanded accordingly. +If that variable does not exist, it silently expands to an empty string. +Consequently, if the intention is to pass a +.Xr sh 1 +variable, it must be surrounded by braces to prevent it from being +considered an internal variable. +.Pp +See +.Sx EXAMPLES +for a detailed example. +.Pp To prevent issues with special shell characters, the following happens for each variable .Ic $foo . @@ -685,6 +705,10 @@ The value of the .Ic foo variable is inserted into the buffer with all single quote characters prefixed by a backslash. +.It +A final +.Dq ' +is inserted. .El .Pp See @@ -788,6 +812,37 @@ detach 0 { }; .Ed .Pp +The following example illustrates the difference betwen internal and shell variables: +.Bd -literal +attach 20 { + device-name "umodem[0-9]+"; + match "vendor" "0x2047"; + match "product" "0x001(0|3|4)"; + match "interface" "0"; + action "cd /dev; p=$product; dn=$device-name; \\ + un=$(sysctl -n dev.umodem.${dn#umodem}.ttyname); \\ + chmod 666 cua${un}; ln -sf cua${un} mspfet${p#0x}"; +}; +.Ed +.Pp +.Dq product , +and +.Dq device-name +are internal variables. +Their contents are initially assigned to shell variables +.Dq p , +and +.Dq dn , +respectively. +Then, variable +.Dq dn +is used inside a shell command substitution, assigning to shell variable +.Dq un . +Finally, this shell variable is used in two other shell statements, where +it needs to be wrapped in braces in order to prevent it from being +considered in internal variable to +.Nm devd . +.Pp The installed .Pa /etc/devd.conf has many additional examples.