Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Nov 2023 07:24:51 -0100
From:      Arthur Chance <freebsd@qeng-ho.org>
To:        D'Arcy Cain <darcy@druid.net>, freebsd-questions@freebsd.org
Subject:   Re: Trying to replace a bashism in bourne sh
Message-ID:  <b7f539c3-860b-4e53-a935-163ffc848115@qeng-ho.org>
In-Reply-To: <48b15ea2-3fd5-4994-aace-f0b8d7dc6ede@qeng-ho.org>
References:  <8cdcb170-1c54-464b-aa89-c89ca98c86ca@druid.net> <48b15ea2-3fd5-4994-aace-f0b8d7dc6ede@qeng-ho.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?b7f539c3-860b-4e53-a935-163ffc848115>