Linux

One-line batch file renamer

If you want to batch rename a bunch of files (say “foo*.jpg” to “bar*.jpg”), you might think you could just do “mv foo*.jpg bar*.jpg” in the Terminal. However, this doesn’t work right since the shell expands each argument before the execution occurs. However, there’s a cool way to accomplish the same result with a (more […]

Read More
Scripting

Bash misc tips

Bash debugging A nice thing to do is to add on the first line #!/bin/bash -x This will produce some interesting output information Reading user input with read In many ocations you may want to prompt the user for some input, and there are several ways to achive this. This is one of those ways: […]

Read More
Linux

Bash user interfaces

Using select to make simple menus #!/bin/bash OPTIONS=”Hello Quit” select opt in $OPTIONS; do if [ “$opt” = “Quit” ]; then echo done exit elif [ “$opt” = “Hello” ]; then echo Hello World else clear echo bad option fi done If you run this script you’ll see that it is a programmer’s dream for […]

Read More
Scripting

Bash functions

As in almost any programming language, you can use functions to group pieces of code in a more logical way or practice the divine art of recursion. Declaring a function is just a matter of writing function my_func { my_code }. Calling a function is just like calling another program, you just write its name. […]

Read More