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

Revised Answer (Feb 12, 2014) the_world_is_flat=true # …do something interesting… if [ “$the_world_is_flat” = true ] ; then echo ‘Be careful not to fall off!’ fi Original Answer Caveats: https://stackoverflow.com/a/21210966/89391 the_world_is_flat=true # …do something interesting… if $the_world_is_flat ; then echo ‘Be careful not to fall off!’ fi From: Using boolean variables in Bash The reason … Read more

How do I parse command line arguments in Bash?

Bash Space-Separated (e.g., –option argument) cat >/tmp/demo-space-separated.sh <<‘EOF’ #!/bin/bash POSITIONAL_ARGS=() while [[ $# -gt 0 ]]; do case $1 in -e|–extension) EXTENSION=”$2″ shift # past argument shift # past value ;; -s|–searchpath) SEARCHPATH=”$2″ shift # past argument shift # past value ;; –default) DEFAULT=YES shift # past argument ;; -*|–*) echo “Unknown option $1” exit … Read more

How to mkdir only if a directory does not already exist?

Try mkdir -p: mkdir -p foo Note that this will also create any intermediate directories that don’t exist; for instance, mkdir -p foo/bar/baz will create directories foo, foo/bar, and foo/bar/baz if they don’t exist. Some implementation like GNU mkdir include mkdir –parents as a more readable alias, but this is not specified in POSIX/Single Unix … Read more

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