Saturday, July 19, 2008

Special character ; at bashprompt

; is used as a command separator and to terminate a case statement at bash

#!/bin/bash

# This script is to explain the usage of the ; as a special character in bash.
# Sijo George
#--------------------------START-------------------------------
echo "Hello world,"; echo "How are you?"; # Execute two commands in a line using a ; delimiter
case $1 in
[a-z] ) echo " The input is an alphabet " ;; # Terminator in the case option
[0-9] ) echo " The input is a number" ;;
* ) echo " The input is neither an alpabet or a number ";;
esac

Thursday, July 17, 2008

Usage of Special character '#' at bash

Read through the script below. This better explains the usage

#!/bin/bash
# This script is to explain the special char #
# Sijo George sijo.george@gmail.com
#------------------START------------------------#
#This is a comment
echo "This is #not a comment"
echo 'This also # is not a comment'
echo But ...This is a #comment
echo However This \# is not a comment
echo "Parameter sub is not a comment"
echo ${PATH}
echo ${PATH#*:};# Cuts of the shortest string of pattern after the # from the front
echo ${PATH##*:};# Cuts of the longest string of pattern after the # from the front
echo "Base conversion is not a comment "
echo $((2#1010)) # Convers binary 1010 to decimal
echo $((16#ABCD)) # Converts hex ABCD to decimal
string="this is a string"
echo ${#string} # Gives the number of characters in the string
array=(1 test a 10)
echo ${#array} # Gives the length of first element of the array
echo ${#array[*]} # Gives the number of elements in the array
echo ${#array[@]} # Gives the number of elements in the array
echo ${#} # Gives the number of command line parameters.
echo ${#*} #Gives the number of command line parameters.
echo ${#@} #Gives the number of command line parameters.