What method should I use to write error messages to ‘stderr’ using ‘printf’ in a bash script?

First, yes, 1>&2 is the right thing to do. Second, the reason your 1>&2 2>errors.txt example doesn’t work is because of the details of exactly what redirection does. 1>&2 means “make filehandle 1 point to wherever filehandle 2 does currently” — i.e. stuff that would have been written to stdout now goes to stderr. 2>errors.txt … Read more

How to write multiple line string using Bash with variables?

The syntax (<<<) and the command used (echo) is wrong. Correct would be: #!/bin/bash kernel=”2.6.39″ distro=”xyz” cat >/etc/myconfig.conf <<EOL line 1, ${kernel} line 2, line 3, ${distro} line 4 line … EOL cat /etc/myconfig.conf This construction is referred to as a Here Document and can be found in the Bash man pages under man –pager=”less … Read more

How to iterate over associative arrays in Bash

The keys are accessed using an exclamation point: ${!array[@]}, the values are accessed using ${array[@]}. You can iterate over the key/value pairs like this: for i in “${!array[@]}” do echo “key : $i” echo “value: ${array[$i]}” done Note the use of quotes around the variable in the for statement (plus the use of @ instead … Read more

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