You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Joachim Ansorg edited this page May 3, 2025
·
2 revisions
Use && for logical AND. Single & will background and return true.
Problematic code:
if [ "$1"="install" ] & [ "$USER"!="root" ]
thenecho"Must be root to install"fi
Correct code:
if [ "$1"="install" ] && [ "$USER"!="root" ]
thenecho"Must be root to install"fi
Rationale:
ShellCheck found a test command followed by a &. This runs the test in the background, effectively ignoring it. To specify "logical AND" between two commands, use &&.
Exceptions:
None
Related resources:
Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!