RE error: illegal byte sequence on Mac OS X

A sample command that exhibits the symptom: sed ‘s/./@/’ <<<$’\xfc’ fails, because byte 0xfc is not a valid UTF-8 char.Note that, by contrast, GNU sed (Linux, but also installable on macOS) simply passes the invalid byte through, without reporting an error. Using the formerly accepted answer is an option if you don’t mind losing support for your true locale (if you’re on a US system … Read more

What does `set -x` do?

set -x enables a mode of the shell where all executed commands are printed to the terminal. In your case it’s clearly used for debugging, which is a typical use case for set -x: printing every command as it is executed may help you to visualize the control flow of the script if it is not functioning … Read more

How can I add numbers in a Bash script?

For integers: Use arithmetic expansion: $((EXPR))num=$((num1 + num2)) num=$(($num1 + $num2)) # Also works num=$((num1 + 2 + 3)) # … num=$[num1+num2] # Old, deprecated arithmetic expression syntax Using the external expr utility. Note that this is only needed for really old systems.num=`expr $num1 + $num2` # Whitespace for expr is important For floating point: Bash doesn’t directly support … Read more

How do I automatically restart a Minecraft Spigot server in the event of a crash or /stop when using screen?

Tutorial A friend wrote a bash script to automatically restart a minecraft (spigot) server in the event of a crash or with the command “/stop” when using screen. There are several seconds to cancel the restart with Enter. In addition, the exit codes of the previous session are written to a file, which can be … Read more

choosing between $0 and BASH_SOURCE

Note: For a POSIX-compliant solution, see this answer. ${BASH_SOURCE[0]} (or, more simply, $BASH_SOURCE[1] ) contains the (potentially relative) path of the containing script in all invocation scenarios, notably also when the script is sourced, which is not true for $0. Furthermore, as Charles Duffy points out, $0 can be set to an arbitrary value by the caller.On the flip side, $BASH_SOURCE can be empty, if no named file is involved; e.g.:echo ‘echo “[$BASH_SOURCE]”‘ | … Read more

Bash script: bad interpreter

The first line, #!/bin/bash, tells Linux where to find the interpreter. The script should also be executable with chmod +x script.sh, which it appears you did. It is highly likely that you created this file with a windows editor, which will place a <cr><lf> at the end of each line. This is the standard under … Read more

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