Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-11-2010
Registered User
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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
}

Sponsored Links
    #2  
Old 03-11-2010
vgersh99's Avatar
ɹoʇɐɹǝpoɯ
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 6,959
Thanks: 69
Thanked 351 Times in 338 Posts

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 02:32 PM.. Reason: added bb code tags for man
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -4. The time now is 03:34 AM.