How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = “Hello”; $foo .= ” World”; Here, $foo becomes “Hello World”. How is this accomplished in Bash? 30 30 foo=”Hello” foo=”${foo} World” echo “${foo}” > Hello World In general to concatenate two variables you can just write them one after another: a=”Hello” b=’World’ c=”${a} ${b}” echo … Read more

Meaning of $? (dollar question mark) in shell scripts

This is the exit status of the last executed command. For example the command true always returns a status of 0 and false always returns a status of 1: true echo $? # echoes 0 false echo $? # echoes 1 From the manual: (acessible by calling man bash in your shell) $?       Expands to the exit status of the most recently executed foreground … Read more

How do I execute a program or call a system command?

How do I call an external command within Python as if I’d typed it in a shell or command prompt? 6 63 Use the subprocess module in the standard library: import subprocess subprocess.run([“ls”, “-l”]) The advantage of subprocess.run over os.system is that it is more flexible (you can get the stdout, stderr, the “real” status … Read more