How can I declare and use Boolean variables in a shell script?

Revised Answer (Feb 12, 2014) Original Answer Caveats: https://stackoverflow.com/a/21210966/89391 From: Using boolean variables in Bash The reason the original answer is included here is because the comments before the revision on Feb 12, 2014 pertain only to the original answer, and many of the comments are wrong when associated with the revised answer. For example, Dennis Williamson’s … Read more

“sed” command in bash

sed is the Stream EDitor. It can do a whole pile of really cool things, but the most common is text replacement. The s,%,$,g part of the command line is the sed command to execute. The s stands for substitute, the , characters are delimiters (other characters can be used; /, : and @ are popular). The % is the pattern to match (here a literal percent sign) and the $ is the second pattern … Read more

What does “-ne” mean in bash?

This is one of those things that can be difficult to search for if you don’t already know where to look. [ is actually a command, not part of the bash shell syntax as you might expect. It happens to be a Bash built-in command, so it’s documented in the Bash manual. There’s also an external … Read more

“while :” vs. “while true” [duplicate]

from manual: : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirections. A zero exit code is returned. As this returns always zero therefore is is similar to be used as true Check out this answer: What Is the Purpose of the `:’ (colon) GNU Bash Builtin?

“unary operator expected” error in Bash if condition

If you know you’re always going to use Bash, it’s much easier to always use the double bracket conditional compound command [[ … ]], instead of the POSIX-compatible single bracket version [ … ]. Inside a [[ … ]] compound, word-splitting and pathname expansion are not applied to words, so you can rely on to compare the value of $aug1 with … Read more

An “and” operator for an “if” statement in Bash

What you have should work, unless ${STATUS} is empty. It would probably be better to do: or It’s hard to say, since you haven’t shown us exactly what is going wrong with your script. Personal opinion: never use [[. It suppresses important error messages and is not portable to different shells.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)