Translate

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/NorwegianÖversätta till Svensk/Swedishहिन्दी अनुवाद करने के लिए/Hindi
Tradueix al català/CatalanTulkot uz latviešu/LatvianPreložiť do slovenčiny/SlovakVertaal aan het Nederlands/Dutchترجمة الى العربية/ArabicTraduzca al Español/SpanishTraduisez au Français/French
Traduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplified中文翻译/Chinese TraditionalПереклад на українську/Ukrainian
Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)
Image of Beginning Google Maps API 3
Image of Android Wireless Application Development
Image of Operating System Concepts

Sort Korn Shell 93 Associative Arrays

This port demonstrates one method of sort printing the elements of an Korn shell associative array.

KSH93 libshell

In a number of posts about a year ago I discussed how to develop custom builtins for Korn Shell 93 (ksh93) using libshell and published APIs. You can also use these same APIs to access ksh93 functionality from within a C application. This post provides three simple examples of how to do this.

KSH93 Message Localization

ksh93 supports localization of internal error messages and getopts messages but localization of user messages in shell scripts is flawed. This post examines the issue and shows you how to easily support shell script message catalogs.

Bootable DVD/CDROM

Have you ever wanted to determine whether a DVD or CDROM is a bootable CDROM or DVD from within a shell script?  If you use GNU/Linux you could parse the output from the isoinfo utility which is part of the CDRecord tools suite.

What if the isoinfo utility is not available on your operating system?  In this case you have to resort to rolling you own compiled langauge utility or shell script.  To do this you need to understand where to find the specific bytes on a CDROM/DVD which indicate whether it is a bootable CDROM/DVD or not.  The relevant specification covering bootable CDROMs (and by extension bootable DVDs) is the El Torito specification which is an extension to the ISO 9660 specification.

Our first shell script uses the dd utility to read in the required bytes which are then sliced and diced using the xxd and cut utilities..  Sector 17 (hexadecimal 11, the Boot Record Volume) contains two bytes at a specific offset which are an absolute pointer to the Booting Catalog which in turn contains a specific byte which indicates whether a CDROM/DVD is bootable or not. #!/bin/bash # # use dd to read in the required bytes # DEVICE=”/dev/sr0″ VERBOSE=1 # get 2 bytes at absolute offset 34887 bchex=`dd if=${DEVICE} skip=$(( 0×800 * 0×11 + 0×47)) bs=1 count=2 conv=swab 2>/dev/null | xxd | cut -d” ” -f2` # get one byte bcdec=`printf “%d” 0x${bchex}` bootable=`dd if=${DEVICE} bs=1 skip=$(( 0×800 * bcdec + 0×20)) count=1 2>/dev/null | xxd | cut -d” ” -f2` if [[ $bootable = 88 ]]; then [ $VERBOSE ] && printf “Bootable CDROM\n” exit 0 else [ $VERBOSE ] && printf “Not a bootable CDROM\n” exit 1 fi

The previous shell script is classical in its approach to the problem in that it uses a number of small specialized utilities to achieve the desired result.

Another way of achieving the same result is to use the extended I/O features of ksh93 as shown in the following shell script. #!/bin/ksh93 # # Cannot open DVD/CDROM for read/write – hence cannot seek # forward on file descriptor. Workaround is to close and # reopen the file descriptor. # DEVICE=”/dev/sr0″ VERBOSE=1 # read 2 bytes redirect 3< $DEVICE || exit 3

KSH93 Bit Manipulation

When programmers think about bitwise manipulation, they usually think about using C or C++ to solve their problem since both programming languages provide a rich set of features which make it easy to perform bitwise manipulation. It is possible to just as easily perform such operations using the Korn shell. This post explains what bitwise manipulation and number conversion facilities are available in ksh93.