Re: bash: return status of an assignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



I think this is a problem with the precedence of && vs ||. If INSMOD is not
set, it will work as you intend, but once it's set, only the || branch will
execute.

You can fix it if you group the assignments together:

[ -z "$INSMOD" ] && (INSMOD=$(which modprobe) || INSMOD="$(which insmod)")

On Sat, Feb 27, 2021 at 01:32:55PM -0800, Kenneth Porter wrote:
> In the sqm-scripts package for managing network traffic shaping is this line
> for finding a program suitable for loading the kernel shaping modules:
> 
> [ -z "$INSMOD" ] && INSMOD=$(which modprobe) || INSMOD=$(which insmod)
> 
> It seems to set INSMOD to /usr/sbin/insmod, even though /usr/sbin/modprobe
> is available. (Both are symlinks to ../bin/kmod.)
> 
> According to this article, the return value of the first assignment should
> be success and it shouldn't take the fallback statement:
> 
> <https://unix.stackexchange.com/questions/270828/how-is-the-return-status-of-a-variable-assignment-determined>
> 
> Also working the issue here:
> 
> <https://github.com/tohojo/sqm-scripts/issues/133>
> 
> _______________________________________________
> CentOS mailing list
> CentOS@xxxxxxxxxx
> https://lists.centos.org/mailman/listinfo/centos

-- 
-- Skylar Thompson (skylar2@xxxxxxxxxxxxxxxx)
-- Genome Sciences Department, System Administrator
-- Foege Building S046, (206)-685-7354
-- University of Washington School of Medicine
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos



[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]


  Powered by Linux