How to read a file into a variable in shell?

In cross-platform, lowest-common-denominator sh you use: #!/bin/sh value=`cat config.txt` echo “$value” In bash or zsh, to read a whole file into a variable without invoking cat: #!/bin/bash value=$(<config.txt) echo “$value” Invoking cat in bash or zsh to slurp a file would be considered a Useless Use of Cat. Note that it is not necessary to … Read more

What does set -e mean in a bash script?

From help set : -e Exit immediately if a command exits with a non-zero status. But it’s considered bad practice by some (bash FAQ and irc freenode #bash FAQ authors). It’s recommended to use: trap ‘do_something’ ERR to run do_something function when errors occur. See http://mywiki.wooledge.org/BashFAQ/105

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

Difference between sh and Bash

What is sh? sh (or the Shell Command Language) is a programming language described by the POSIX standard. It has many implementations (ksh88, Dash, …). Bash can also be considered an implementation of sh (see below). Because sh is a specification, not an implementation, /bin/sh is a symlink (or a hard link) to an actual … Read more

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