What is #0 ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is #0 ?
# 1  
Old 03-11-2010
What is #0 ?

In this below function, I am trying to understand what is the purpose of
H1=${H1#0} ?
This is ksh. Any improvement to below function are also appreciated.

Code:
dateDiff(){
   echo enter first time stamp
   TIME1=`date +%H:%M:%S`
   echo enter second time stamp
   TIME2=23:59:59
   H1=`date +%H`
   echo "Hour="$H1
   M1=`date +%M`
   echo "Mintue="$M1
   S1=`date +%S`
   H2=23
   M2=59
   S2=59
   H1=${H1#0}
   M1=${M1#0}
   H2=${H2#0}
   M2=${M2#0}
   ((MAM1=H1+(M1/60)+(S1/3600)))
   ((MAM2=H2+(M2/60)+(S2/3600)))
   ((diff=MAM2-MAM1))
   echo diff = $diff
   return $diff
}

# 2  
Old 03-11-2010
Code:
$ a='00abc'
$ echo ${a#0}
0abc

man ksh yields the following:
Code:
     The following four varieties of parameter expansion  provide
     for  substring  processing.  In  each case, pattern matching
     notation (see patmat), rather than regular expression  nota-
     tion, will be used to evaluate the patterns. If parameter is
     * or @, then all the positional  parameters,  starting  with
     $1,  are substituted (separated by a field separator charac-
     ter). Enclosing  the  full  parameter  expansion  string  in
     double-quotes will not cause the following four varieties of
     pattern characters to be quoted, whereas quoting  characters
     within the braces will have this effect.

     ${parameter%word}
           Remove Smallest  Suffix  Pattern.  The  word  will  be
           expanded to produce a pattern. The parameter expansion
           then will result in parameter, with the smallest  por-
           tion of the suffix matched by the pattern deleted.

     ${parameter%%word}
           Remove  Largest  Suffix  Pattern.  The  word  will  be
           expanded to produce a pattern. The parameter expansion
           then will result in parameter, with the  largest  por-
           tion of the suffix matched by the pattern deleted.

     ${parameter#word}
           Remove Smallest  Prefix  Pattern.  The  word  will  be
           expanded to produce a pattern. The parameter expansion
           then will result in parameter, with the smallest  por-
           tion of the prefix matched by the pattern deleted.

     ${parameter##word}
           Remove  Largest  Prefix  Pattern.  The  word  will  be
           expanded to produce a pattern. The parameter expansion
           then will result in parameter, with the  largest  por-
           tion of the prefix matched by the pattern deleted.


Last edited by Neo; 03-11-2010 at 03:32 PM.. Reason: added bb code tags for man
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question