shadow: don't use <cond> && <cmd> for conditional

Explain why in a comment.
This commit is contained in:
Pierre Labastie 2022-11-16 16:42:25 +01:00
parent 4635a45ddb
commit ae27cdcfc9

View File

@ -557,8 +557,18 @@ done</userinput></screen>
<indexterm zone="shadow pam-access">
<primary sortas="e-etc-security-access.conf">/etc/security/access.conf</primary>
</indexterm>
<screen role="root"><userinput>[ -f /etc/login.access ] &amp;&amp; mv -v /etc/login.access{,.NOUSE}</userinput></screen>
<!-- to editors: it is a common belief that:
if <condition>; then <command>; fi
is equivalent to:
<condition> && <command>
This is not true in bash; try:
([ 0 = 1 ] && echo not reachable); echo $? # echoes 1
vs
(if [ 0 = 1 ]; then echo not reachable; fi); echo $? # echoes 0
So in scripts that may call subshells (for example through sudo) and
that need error reporting, the outcome _is_ different. In all
cases, for bash, the "if" form should be preferred.-->
<screen role="root"><userinput>if [ -f /etc/login.access ]; then mv -v /etc/login.access{,.NOUSE}; fi</userinput></screen>
</sect4>
<sect4 id="pam-limits">
@ -577,7 +587,7 @@ done</userinput></screen>
<primary sortas="e-etc-security-limits.conf">/etc/security/limits.conf</primary>
</indexterm>
<screen role="root"><userinput>[ -f /etc/limits ] &amp;&amp; mv -v /etc/limits{,.NOUSE}</userinput></screen>
<screen role="root"><userinput>if [ -f /etc/limits ]; then mv -v /etc/limits{,.NOUSE}; fi</userinput></screen>
<caution>
<para>