Archive for 'Shell'

Indenting bourne shell here documents

The Bourne shell provides here documents to allow block of data to be passed to a process through STDIN. The typical format for a here document is something similar to this: command <<ARBITRARY_TAG data to pass 1 data to pass 2 ARBITRARY_TAG This will send the data between the ARBITRARY_TAG statements to the standard input [...]

Exiting from a shell script when a failure occurs

While debugging an issue with one of my scripts, I wanted to abort execution and exit when a non-zero return code occurred. I recalled reading about a bash flag that provided this behaviour, and after a few minutes of reading through bash(1) I came across the following set option: “-e Exit immediately if a simple [...]

Getting sed to substitute a newline on Linux and Solaris hosts

While crafting an install script a week or two ago, I came across an annoying issue with the Solaris sed utility. When I tried to substitute the string ‘, ‘ with a newline, I got this: $ grep foo gemlist | sed -e ‘s/foo.*(//’ -e ‘s/)//’ -e ‘s/, /\n/g’ 2.4n2.3n2.2n2.1 But when I ran the [...]

Bash tips

I read through the bash tips on the hacktux website, which brought to light the fact that you can do basic integer math in your bash scripts. This is easily accomplished by using dual parenthesis similar to this: four=$(( 2 + 2 )) echo $four This is good stuff, and I need to replace some [...]

  Recent Entries »