ShellCheck does not detect error? How to fix my snippet?
0
votes
1
answer
221
views
I likely have syntax errors in the following (POSIX) shell snippet:
#!/bin/sh
if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none;
elif tput AF >/dev/null 2>&1; then tput_init_bsd else tput_init_none;
else tput_init_none; fi
ShellCheck 0.10.0 does say nothing about it, I found it basically by accident.
I tested as follows:
1)
if tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; fi
this went ok: tput_init_linux: command not found
2) Reverting the logic with !
:
if ! tput setaf >/dev/null 2>&1; then tput_init_linux else tput_init_none; fi
**says nothing**, but if I add one semicolon:
3)
if ! tput setaf >/dev/null 2>&1; then tput_init_linux; else tput_init_none; fi
it appears to work as expected: tput_init_none: command not found
***
But I seem to be unable to chain these multiple if
-statements afterward.
***
So as you can see, I reached a state, where one statement works, but chaining it seems _problematic_. Can anyone help?
Asked by Vlastimil Burián
(30505 rep)
May 23, 2024, 07:08 AM
Last activity: May 24, 2024, 10:38 AM
Last activity: May 24, 2024, 10:38 AM