Translate

Image of Beginning Google Maps API 3
Image of XSLT 2.0 and XPath 2.0 Programmer's Reference (Programmer to Programmer)
Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)
Image of Android Wireless Application Development

Dynamically Updating Xterm Title using Ksh93

In this post, I show you how to use a discipline function dynamically customize the title of your xterm window and your shell prompt

Korn Shell DEBUG Trap

The trap shell builtin is used to change the way signals are handled by the Korn Shell 93 (ksh93) shell. In addition, a trap may be set for three ksh93 pseudo-signals: EXIT, ERR, and DEBUG. In this post we demonstrate how to use the DEBUG pseudo-signal to trap changes in the value of a variable for debugging purposes. trap [ -p ] [ action ] [ sig ] . . . The -p option causes the trap action associated with each trap as specified by the arguments to be printed with appropriate quoting. Otherwise, action will be processed as if

Convert Integer to Float in Korn Shell

There is no explicit mechanism, such as float(integer), in the Korn Shell (ksh93) to convert an integer to a float which in the Korn Shell is by default a long double. By default, dividing integer 1 by 3 produces 0: $ integer x=1 $ echo $(( x/3 )) 0 $ So how to you get the result, 0.3333 …, which you probably were expecting? You can convert x to floating point and then do the division by replacing the 3 with either 3. or, as I normally do, with 3.0: $ integer x=1 $ echo $(( x/3. )) 0.333333333333333333 $

Implementing strstr in Korn Shell

Neither Bash or the Korn Shell 93 (ksh93) provide a C-like strstr builtin. Here is a simple implementation of a strstr function in ksh93. The strstr function finds the first occurrence of s2 in s1. If s2 is an empty string, 0 is returned; if s2 occurs nowhere in s1, 0 is also returned; otherwise the offset to the first character of the first occurrence of s2 is returned. #!/bin/ksh function strstr { typeset s1=”$1″ typeset s2=”$2″ if [[ ${#s2} == 0 ]] then return 0 fi typeset len=${#s1} typeset first=${s1%%${s2}*}x typeset ndx=${#first} if (( ndx > len )) then

First Letter Capitalization in Bash and Korn Shell

Bash does not have a built-in facility to first letter capitalize a string but Bash 4.0 and later has the necessary tools to do so as shown by the following example: #!/bin/bash Firstcap() { lower=${1,,} echo ${lower^} } Firstcap lINUX >>> OUTPUT IS: Linux This function not only uppercases the first letter of the argument passed to it but also lowercases the remaining letters of the argument. Here is how to do the same thing in ksh93: #!/bin/ksh Firstcap() { typeset -u f f=${1:0:1} typeset -l r r=${1:1} echo “${f}${r}” } Firstcap lINUX >>> OUTPUT IS: Linux