From nobody Tue Nov 07 08:24:51 2023 X-Original-To: freebsd-questions@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 4SPh935sRPz50Kmt for ; Tue, 7 Nov 2023 08:24:55 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from mailout.qeng-ho.org (mailout.qeng-ho.org [217.155.128.244]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4SPh925Pjnz3CMy for ; Tue, 7 Nov 2023 08:24:54 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of freebsd@qeng-ho.org designates 217.155.128.244 as permitted sender) smtp.mailfrom=freebsd@qeng-ho.org; dmarc=none Received: from [IPV6:2a02:8010:64c9:1::2] (unknown [IPv6:2a02:8010:64c9:1::2]) by mailout.qeng-ho.org (Postfix) with ESMTP id A91A7F6A90; Tue, 7 Nov 2023 08:24:53 +0000 (GMT) Message-ID: Date: Tue, 7 Nov 2023 07:24:51 -0100 List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Trying to replace a bashism in bourne sh Content-Language: en-GB From: Arthur Chance To: D'Arcy Cain , freebsd-questions@freebsd.org References: <8cdcb170-1c54-464b-aa89-c89ca98c86ca@druid.net> <48b15ea2-3fd5-4994-aace-f0b8d7dc6ede@qeng-ho.org> In-Reply-To: <48b15ea2-3fd5-4994-aace-f0b8d7dc6ede@qeng-ho.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-3.28 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-0.998]; NEURAL_HAM_SHORT(-0.99)[-0.992]; R_SPF_ALLOW(-0.20)[+ip4:217.155.128.240/29]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; ASN(0.00)[asn:13037, ipnet:217.155.0.0/16, country:GB]; MLMMJ_DEST(0.00)[freebsd-questions@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_TLS_LAST(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[]; DMARC_NA(0.00)[qeng-ho.org]; MID_RHS_MATCH_FROM(0.00)[] X-Rspamd-Queue-Id: 4SPh925Pjnz3CMy X-Spamd-Bar: --- On 07/11/2023 07:21, Arthur Chance wrote: > On 06/11/2023 18:45, D'Arcy Cain wrote: >> I need to do this; >> >>   ifconfig_eth3="inet $((16#c0a8c0${me} + 100))/24" >> >> Problem is that I need to do this at boot time but then it runs as >> bourne sh.  Does anyone have an equivalent for sh? > > I'm not totally familiar with bash but that (16#c0a8c0) is a hexadecimal > number equivalent to an address triplet 192.168.192. I'd guess ${me} is > also a 2 digit hex value and for some reason 100 is added. The whole > thing is assembling an IPv4 CIDR network address (the /24 is the netmask > bit). Try something along the lines of > > ifconfig_eth3="192.168.192."$((me_in_decimal+100))"/24" Always reread twice. That should of course be ifconfig_eth3="inet 192.168.192."$((me_in_decimal+100))"/24" > > if you can arrange for ${me} to be specified in decimal rather than hex. > If you can't then something like > > ifconfig_eth3="192.168.192."$(hex_to_decimal_plus_100 ${me})"/24" and this ifconfig_eth3="inet 192.168.192."$(hex_to_decimal_plus_100 ${me})"/24" > where implementing the function hex_to_decimal_plus_100 is left as an > exercise for the reader. :-) > -- We build our computer systems the way we build our cities; over time, without a plan, on top of ruins. — Ellen Ullman