Translate

Archives

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

Bash and Korn Shell Let Keyword

Recently a colleague of mine recommended using the let keyword in shell scripts to perform arithmetic evaluation. That prompted me to write this post about the let keyword. Here is what the bash manpage says about the let keyword: let arg [arg …] Each arg is an arithmetic expression to be evaluated. If the last arg evaluates to 0, let returns 1; 0 is returned otherwise. And here is a simple example of it’s use: $ a=2 $ b=5 $ let c=$a+$b $ echo $c 7 $ let c=$a + $b $ echo $c 2 As you can see from

Shell Script: Print Hexadecimal Representation of String

This post discusses how to print out the numeric value of a character in the underlying codeset in a shell script.