Date: Tue, 7 Nov 2023 07:21:03 -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: <48b15ea2-3fd5-4994-aace-f0b8d7dc6ede@qeng-ho.org> In-Reply-To: <8cdcb170-1c54-464b-aa89-c89ca98c86ca@druid.net> References: <8cdcb170-1c54-464b-aa89-c89ca98c86ca@druid.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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" 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" 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?48b15ea2-3fd5-4994-aace-f0b8d7dc6ede>