Best practice for exiting batch file?

Personally I use exit. The normal exit command simply terminates the current script, and the parent (for example if you were running a script from command line, or calling it from another batch file) exit /b is used to terminate the current script, but leaves the parent window/script/calling label open. With exit, you can also add an error level … Read more

Error handling in Bash

Use a trap! …then, whenever you create a temporary file: and $temp_foo will be deleted on exit, and the current line number will be printed. (set -e will likewise give you exit-on-error behavior, though it comes with serious caveats and weakens code’s predictability and portability). You can either let the trap call error for you (in which case it uses the default … Read more

Windows batch – concatenate multiple text files into one

Windows type command works similarly to UNIX cat. Example 1: Merge with file names (This will merge file1.csv & file2.csv to create concat.csv) Example 2: Merge files with pattern (This will merge all files with csv extension and create concat.csv) When using asterisk(*) to concatenate all files. Please DON’T use same extension for target file(Eg. .csv). There should be some difference … Read more

Test or check if sheet exists

Some folk dislike this approach because of an “inappropriate” use of error handling, but I think it’s considered acceptable in VBA… An alternative approach is to loop though all the sheets until you find a match.

Shell script not running, command not found

I am very, very new to UNIX programming (running on MacOSX Mountain Lion via Terminal). I’ve been learning the basics from a bioinformatics and molecular methods course (we’ve had two classes) where we will eventually be using perl and python for data management purposes. Anyway, we have been tasked with writing a shell script to … Read more

Purpose of #!/usr/bin/python3 shebang

#!/usr/bin/python3 is a shebang line. A shebang line defines where the interpreter is located. In this case, the python3 interpreter is located in /usr/bin/python3. A shebang line could also be a bash, ruby, perl or any other scripting languages’ interpreter, for example: #!/bin/bash. Without the shebang line, the operating system does not know it’s a python script, even if you set the execution flag (chmod … Read more