Using conditional statements inside ‘expect’

Have to recomment the Exploring Expect book for all expect programmers — invaluable. I’ve rewritten your code: (untested) proc login {user pass} { expect “login:” send “$user\r” expect “password:” send “$pass\r” } set username spongebob set passwords {squarepants rhombuspants} set index 0 spawn telnet 192.168.40.100 login $username [lindex $passwords $index] expect { “login incorrect” { … Read more

Multidimensional associative arrays in Bash

You can’t do what you’re trying to do: bash arrays are one-dimensional $ declare -A PERSONS $ declare -A PERSON $ PERSON[“FNAME”]=’John’ $ PERSON[“LNAME”]=’Andrew’ $ declare -p PERSON declare -A PERSON='([FNAME]=”John” [LNAME]=”Andrew” )’ $ PERSONS[1]=([FNAME]=”John” [LNAME]=”Andrew” ) bash: PERSONS[1]: cannot assign list to array member You can fake multidimensionality by composing a suitable array index … Read more

using jq to assign multiple output variables

You can use separate variables with read : read var1 var2 var3 < <(echo $(curl -s ‘https://api.github.com/repos/torvalds/linux’ | jq -r ‘.id, .name, .full_name’)) echo “id : $var1” echo “name : $var2” echo “full_name : $var3” Using array : read -a arr < <(echo $(curl -s ‘https://api.github.com/repos/torvalds/linux’ | jq -r ‘.id, .name, .full_name’)) echo “id : … Read more

Comparing PHP version numbers using Bash?

Here’s how to compare versions. using sort -V: function version_gt() { test “$(printf ‘%s\n’ “$@” | sort -V | head -n 1)” != “$1”; } example usage: first_version=5.100.2 second_version=5.1.2 if version_gt $first_version $second_version; then echo “$first_version is greater than $second_version !” fi pro: solid way to compare fancy version strings: support any length of sub-parts … Read more

How to match a single quote in sed

You can either use: “texta’textb” (APOSTROPHE inside QUOTATION MARKs) or ‘texta’\”textb’ (APOSTROPHE text APOSTROPHE, then REVERSE SOLIDUS, APOSTROPHE, then APOSTROPHE more text APOSTROPHE) I used unicode character names. REVERSE SOLIDUS is more commonly known as backslash. In the latter case, you close your apostrophe, then shell-quote your apostrophe with a backslash, then open another apostrophe … Read more

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