From nobody Fri Dec 20 20:21:00 2024 X-Original-To: dev-commits-src-all@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 4YFJhY0D0Nz5Yyh2; Fri, 20 Dec 2024 20:21:01 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YFJhX6qZKz4RnB; Fri, 20 Dec 2024 20:21:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734726061; 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=7cly4Zx0Gu/WUfwd2wDcrr72Odm3LRpGJtyy0NOg8EU=; b=EoFpHEktrSobrAbSeoA55CysuWY36qyuJSGUnBglJaRT5AdzaLfUvXLO4CE8WFRpki0i1d +ApSMuXYmOFxhbUzDILZxfzD7GtgIY3Vvt5FdeVc8x+AFm8fsa50eHQ91sgnJiLqweityv rEFTW6wkOnIfb4ntSRj5pbv5ySvGfJoGzNc68xIr+q+OesS4m0peP5fIl6HzNFDzzYpKan dymFYTQ6kwqBP/RtgkHwIEbxiqMphUtD5u2jLyGtloyqdNY1/iSMkrLqbgrV0S4/s8tUgQ pmopCr91waJQePA+yyhMzm5C1lqHxSfZhHcVDSefn+yyi4S/cDFBUt6gJAhMPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734726061; 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=7cly4Zx0Gu/WUfwd2wDcrr72Odm3LRpGJtyy0NOg8EU=; b=YZtl8k0rAUmxSMdD5DwO4O5IeFVtWC57Sn/HrlqVjQ60gUime213dnBfd3DgT+1nnzKRKu wKi5biim19k/L5ApTCvkq89fHY5RLe4oPgypOj7KFr7N2cs2WZNKkd/Ia/EFNKpKr+VD4T Y0FCEC4Q4zrpMwshGOpGPlScJgjWRzQpbMlS1amcs6PAbH8n/nf8ocFTX4sDfnKCYFn87H mtSvXvSgRP/RgTS3MfICnNDUFecum+APQtcbhmVK5A2uEJ8Vcsch5i7wFfkEuM3WzR3EZY MrwzRU+eI1xf9DQpdXBlMldDDq29n/yyJeuh8qZYN59F/o7JiO5SSkzVcF+iwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734726061; a=rsa-sha256; cv=none; b=tEg7r5t263eLJfvudXVk1XcoyVgpgvBcGGiXYtRK+Apu9Vs/zFImqmZgx7I8BZWr8YR1SY fBxZVMz5bPU+OxZxG5TzTHaYXQdVvH2ayctouKQkN51LlPV5K6DYZOlGNkqY27Vj5vULoF b1cxEGelg5zQzwHW4In4WcsHRE/NaAS+fenFhE5yYN3lf/pUKzrEUrzaDJCfZkdolp2pD4 23eFyzP8YLkc+fHseOyBzaH11MuQrmnLRagWnja1f1/00isqcjvs+55CIVNKrqQpl2s5Wy lY1prgtYM3S1h1y2gJgxk3k4h7x6JQ0MJQhv3SUMSU2AXNugPgYJv8vVEgaMcQ== 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 4YFJhX6H0bzswt; Fri, 20 Dec 2024 20:21:00 +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 4BKKL0PO041784; Fri, 20 Dec 2024 20:21:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BKKL03E041781; Fri, 20 Dec 2024 20:21:00 GMT (envelope-from git) Date: Fri, 20 Dec 2024 20:21:00 GMT Message-Id: <202412202021.4BKKL03E041781@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Joerg Wunsch Subject: git: 1fc7922f9f90 - main - devd.conf(5): explain difference between internal and shell variables List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 1fc7922f9f905b62ef9a6c03be498c282e7b382e Auto-Submitted: auto-generated The branch main has been updated by joerg: URL: https://cgit.FreeBSD.org/src/commit/?id=1fc7922f9f905b62ef9a6c03be498c282e7b382e commit 1fc7922f9f905b62ef9a6c03be498c282e7b382e Author: Joerg Wunsch AuthorDate: 2024-12-20 20:16:52 +0000 Commit: Joerg Wunsch CommitDate: 2024-12-20 20:20:50 +0000 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 MFC after: 1 week Differential Revision: --- 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 ceff27e8be60..5027ce78eae0 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 March 6, 2024 +.Dd December 20, 2024 .Dt DEVD.CONF 5 .Os .Sh NAME @@ -694,6 +694,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 . @@ -711,6 +731,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 @@ -822,6 +846,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.