Translate

Archives

Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
Image of XSLT 2.0 and XPath 2.0 Programmer's Reference (Programmer to Programmer)
Image of Beginning Google Maps API 3
Image of Operating System Concepts

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

Korn Shell Ordinal Number Conversion

It is useful to be able to convert to and from ASCII ordinal numbers in scripts. Here is one way of doing it in Korn shell scripts. To convert the character ‘F’ to it’s ASCII ordinal value: $ print $((‘F’)) 70 To display the ASCII character associated with the ordinal number 70: $ typeset -i8 c=70 $ printf “\${c#*#}n” F

Bash XOR A String

Here is an example of how to XOR a string variable using the Bash shell. Each character in the plaintext string is XOR’ed with decimal 90. #!/usr/local/bin/bash plaintext="abcdefg" echo "Plaintext: $plaintext" cyphertext="" for ((i=0; i < ${#plaintext}; i++ )) do ord=$(printf "%d" "’${plaintext:$i:1}") tmp=$(printf \$(printf ‘%03o’ $((ord ^ 90)) )) ciphertext="${ciphertext}${tmp}" done echo "Ciphertext: $ciphertext" # now XOR again and we should get the original string back plaintext="" for ((i=0; i < ${#ciphertext}; i++ )) do ord=$(printf "%d" "’${ciphertext:$i:1}") tmp=$(printf \$(printf ‘%03o’ $((ord ^ 90)) )) plaintext="${plaintext}${tmp}" done echo "Plaintext: $plaintext" The key lines are the ord= and the tmp=

Porting KSH93 to Windows 7 SUA

This post shows you how to download, build and install the latest version of the Korn shell in the Windows 7 SUA subsystem.

Korn Shell 93 Hash Builtins

This post shows you how to incorporate hash functions built into the AT&T Advanced Software Technologies (AST) libsum library in your Korn shell shell scripts via custom builtins in a dynamically loadable plugin.