New answers tagged

2

Answers to your questions Should the main be broken into more functions? Yes. Keep it as high level as possible. Basically, it should look like: int main() { char sentence[...]; while (fgets(sentence, sizeof sentence, stdin) != NULL) { processSentence(sentence); } } Where processSentence() would do everything necessary to process a single ...


1

Changes: Quote variables unless you have a good reason not to quote them. How about a password * $(touch /tmp/sorry) * ? Use ${parameter:-word} for turning an empty vaultenv into prod. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. Translate uppercase to lowercase only once. Use ${...


1

Use a shebang #!/usr/bin/env bash I see you're already doing that. In bash, prefer [[...]] over [...]. The double bracket conditional command gives you more features (including regular expression matching), and fewer surprises (particularly about unquoted variables). With a getopts loop, I prefer to shift at the end: while getopts ...; do case $opt in ...


2

The only part I would change are the nested if-statements. Use case: CurrntTime="some_timestamp" MachineName="some_host" for retval in 0 255 2 1 8; do echo "Testing exitcode ${retval}" case ${retval} in 0) echo "$CurrntTime $MachineName : SSH connection is Up";; 255) echo "$...


Top 50 recent answers are included