How to handle missing args in shell script

Typical shell scripts begin by parsing the options and arguments passed on the command line. The number of arguments is stored in the # parameter, i.e., you get it with $#. For example, if your scripts requires exactly three arguments, you can do something like this: if [ $# -lt 3 ]; then echo 1>&2 … Read more

What are shell form and exec form?

The docker shell syntax (which is just a string as the RUN, ENTRYPOINT, and CMD) will run that string as the parameter to /bin/sh -c. This gives you a shell to expand variables, sub commands, piping output, chaining commands together, and other shell conveniences. RUN ls * | grep $trigger_filename || echo file missing && … Read more

Get current directory and concatenate a path

Sounds like you want: path=”$(pwd)/some/path” The $( opens a subshell (and the ) closes it) where the contents are executed as a script so any outputs are put in that location in the string. More useful often is getting the directory of the script that is running: dot=”$(cd “$(dirname “$0″)”; pwd)” path=”$dot/some/path” That’s more useful … Read more

pip is not uninstalling packages

You can always manually delete the packages; you can run: sudo rm -rf /usr/local/lib/python2.7/dist-packages/twitter to remove that package from your dist-packages directory. You may have to edit the easy-install.pth file in the same directory and remove the twitter entry from it.

Number of fields returned by awk

The NF variable is set to the total number of fields in the input record. So: echo “a b c d” | awk –field-separator=” ” “{ print NF }” will display 4 Note, however, that: echo -e “a b c d\na b” | awk –field-separator=” ” “{ print NF }” will display: 4 2 Hope … Read more

How to get the realtime output for a shell command in golang?

Looks like ffmpeg sends all diagnostic messages (the “console output”) to stderr instead of stdout. Below code works for me. package main import ( “bufio” “fmt” “os/exec” “strings” ) func main() { args := “-i test.mp4 -acodec copy -vcodec copy -f flv rtmp://aaa/bbb” cmd := exec.Command(“ffmpeg”, strings.Split(args, ” “)…) stderr, _ := cmd.StderrPipe() cmd.Start() scanner … Read more