Re: Trying to replace a bashism in bourne sh
- In reply to: Arthur Chance : "Re: Trying to replace a bashism in bourne sh"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 07 Nov 2023 08:24:51 UTC
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