Posts

Showing posts with the label Scripting

Bash Throws Error, Line 8: $1: Unbound Variable

Answer : set -u will abort exactly as you describe if you reference a variable which has not been set. You are invoking your script with no arguments, so get_percent is being invoked with no arguments, causing $1 to be unset. Either check for this before invoking your function, or use default expansions ( ${1-default} will expand to default if not already set to something else). This is the effect of set -u . You could check $# inside the function and avoid referencing $1 if it is not set. With $# you can access the number of parameters. In global context it is the number of parameters to the script, in a function it is the number of parameters to the function. In the context of the question, it is if [ $# -ge 1 ] && [ -n "$1" ] then df -h $1 | tail -n +2 | awk '{ print $1,"\t",$5 }' else df -h | tail -n +2 | awk '{ print $1,"\t",$5 }' fi Note that you have to use [ $# -ge 1 ] && [ -n "$...

Choosing A Windows Automation Scripting Language. AutoIt Vs Autohotkey

Answer : I think AutoHotkey's GUI implementation is easier to use like many of its commands. AutoHotkey (no longer maintained) has 3 forks : AutoHotkey v1.1.* (previously known as AutoHotkey_L) has COM, Unicode support, object-oriented -like syntax, arrays, and more. AutoHotkeyCE works on Windows mobile PDA's and smartphones (unfinished, no longer maintained). IronAHK, a .NET version of AutoHotkey (unfinished, no longer maintained). AutoHotkey includes a DLL file that you can call from other programming languages (so does AutoIt). AutoHotkey is open source, AutoIt is not. You have to search the AutoHotkey site to put all tools together. AutoIt does better at packaging all in its initial download. My vote is for AutoHotkey (AHK). 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 ...

Batch Character Escaping

Answer : This is adapted with permission of the author from the page Batch files - Escape Characters on Rob van der Woude's Scripting Pages site. TLDR Windows (and DOS) batch file character escaping is complicated: Much like the universe, if anyone ever does fully come to understand Batch then the language will instantly be replaced by an infinitely weirder and more complex version of itself. This has obviously happened at least once before ;) Percent Sign % % can be escaped as %% – "May not always be required [to be escaped] in doublequoted strings, just try" Generally, Use a Caret ^ These characters "may not always be required [to be escaped] in doublequoted strings, but it won't hurt": ^ & < > | Example: echo a ^> b to print a > b on screen ' is "required [to be escaped] only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used" ` is "required [to be es...