Python script header

First, any time you run a script using the interpreter explicitly, as in the #! line is always ignored. The #! line is a Unix feature of executable scripts only, and you can see it documented in full on the man page for execve(2). There you will find that the word following #! must be the pathname of a valid executable. So executes whatever python is on … 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

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

Choosing a Windows automation scripting language. AutoIt vs Autohotkey

I’ve used both very much. AutoHotKey is very good at managing hotkeys and basic GUI automation. It’s syntax is horrible and it’s not meant for bigger applications. AutoIt has almost every feature AutoHotKey has and much more. COM-automation support, arrays and a pretty nice UDF (User Defined Functions) library. It’s harder to build complex hotkeys … Read more

What is the $? (dollar question mark) variable in shell scripting?

$? is used to find the return value of the last executed command. Try the following in the shell: If somefile exists (regardless whether it is a file or directory), you will get the return value thrown by the ls command, which should be 0 (default “success” return value). If it doesn’t exist, you should get a number other then 0. The … 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: From the manual: (acessible by calling man bash in your shell) $?       Expands to the exit status of the most recently executed foreground pipeline. By convention an exit status of 0 means success, and non-zero return status … Read more

How does “cat << EOF" work in bash?

This is called heredoc format to provide a string into stdin. See https://en.wikipedia.org/wiki/Here_document#Unix_shells for more details. From man bash: Here Documents This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the … Read more