Archive for 'UNIX Shell'

Printing items before PS1

While perusing the bash documentation, I came across the PROMPT_COMMAND variable. If PROMPT_COMMAND is set, bash will execute the command assigned to the variable prior to displaying PS1: $ export PROMPT_COMMAND=”echo \”straight pimpin\”” straight pimpin $ As you can see from this example, this is super useful. ;)

Fixing typos with bash

I frequently find myself make silly typing mistakes when changing between directories. Since this is especially annoying with long directory names, I use the bash cdspell option to transparently fix my typing mistakes. To set this nifty option, you can add the following line to your .bash_profile: $ grep cdspell .bash_profile shopt -s cdspell This [...]

Amusing UNIX commands

While surfing the net this week, I came across a website with a list of several amusing UNIX command lines. I think my personal favorite is “man: why did you get a divorce?”: % man: why did you get a divorce? man:: Too many arguments. It’s all about a little humor! :)

How long has a shell been active?

While reading through the bash documentation I came across the SECONDS variable: $ echo $SECONDS 33 which provides the number of seconds a shell has been active. It is amazing how many useful nuggets of information are located in the bash documentation.

Shifting with bash

While reading through the bash documentation last night I came across “let,” “>>” and “ allows you to shift a value X bits to the right. This sure beats running xcalc and/or bc.

Calculating variable sizes with bash

While perusing the bash documentation today I came across the ${#} built-in, which can be used to view the size of a variable: $ foo=”some number of characters” $ echo ${#foo} 25 This could be useful for iterating through strings in a loop, and is now part of my shell programming crib notes. Niiiiiiiiiiiiiiiiice!

« Older Entries   Recent Entries »