code fragment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting code fragment
# 1  
Old 03-12-2008
code fragment

Hi

I'm looking at some old unix code and, need some help figuring out some of the commands. Here is the line that I'm having trouble with:

echo "$(date) ${0##*/} started" >> $summary.log

I know the first statement prints out the date but, I don't understand the second command on the line ${0##*/} - what is this doing? I know $0 is the script name but, I don't know what the rest of the command should print out. I know this is very old code -- does anyone know what the command ${0##*/} is supposed to echo out?

tia
# 2  
Old 03-13-2008
for me it outputs the current shell.
Wed Mar 12 23:40:00 EDT 2008 bash started
# 3  
Old 03-13-2008
Quote:
Originally Posted by stonemonolith
Hi

I'm looking at some old unix code and, need some help figuring out some of the commands. Here is the line that I'm having trouble with:

echo "$(date) ${0##*/} started" >> $summary.log

I know the first statement prints out the date but, I don't understand the second command on the line ${0##*/} - what is this doing? I know $0 is the script name but, I don't know what the rest of the command should print out. I know this is very old code -- does anyone know what the command ${0##*/} is supposed to echo out?

tia
Try the man pages. Here is what man sh (Section: Parameter Expansion)had to say
Code:
       ${parameter#word}
       ${parameter##word}
              The word is expanded to produce a pattern just as  in  pathname
              expansion.   If  the pattern matches the beginning of the value
              of parameter, then the result of the expansion is the  expanded
              value  of  parameter  with  the  shortest matching pattern (the
              ''#'' case) or the longest matching pattern (the  ''##''  case)
              deleted.  If parameter is @ or *, the pattern removal operation
              is applied to each positional parameter in turn, and the expan-
              sion  is the resultant list.  If parameter is an array variable
              subscripted with @ or  *,  the  pattern  removal  operation  is
              applied  to each member of the array in turn, and the expansion
              is the resultant list.

In your case, $0 would translate to the current shell's path. Like /bin/bash or /bin/ksh or /usr/bin/sh or whichever it is.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script from fragment

Dear friends, I wrote a bash fragment that displays the a file, or creates a file with intermediate directories in the absence of such a file. ] && cat FILE || touch FILE I want to do the same thing, but in bash script. May you explain me how to do that kind of thing. Thank you very-very... (2 Replies)
Discussion started by: Jake999
2 Replies

2. HP-UX

About Block Size and Fragment Size

Accordingly a lot of manuals - if you have block size 8KB and trying to write a 1KB file to the block, as result you waste 7KB of the block space. But recently I noticed about Fragments of File Block. In same case if you have File Block 8KB and Fragment size 1KB - you can save your block space,... (6 Replies)
Discussion started by: jess_t03
6 Replies

3. UNIX for Advanced & Expert Users

Physical disk IO size smaller than fragment block filesystem size ?

Hello, in one default UFS filesystem we have 8K block size (bsize) and 1K fragmentsize (fsize). At this scenary I thought all "FileSytem IO" will be 8K (or greater) but never smaller than the fragment size (1K). If a UFS fragment/blocksize is allwasy several ADJACENTS sectors on disk (in a ... (4 Replies)
Discussion started by: rarino2
4 Replies

4. Linux

Go to a line of code , skip few lines of code

Hi , I have a code where i am using a infinite while loop . some thing like below while do if then #go to line 20 fi command 1; command 2; #line 20: sleep 34; (5 Replies)
Discussion started by: Paarth
5 Replies

5. Shell Programming and Scripting

Block of code replacement in Java source code through Unix script

Hi, I want to remove the following code from Source files (or replace the code with empty.) from all the source files in given directory. finally { if (null != hibernateSession && hibernateSession.isOpen()) { //hibernateSession.close(); } } It would be great if the script has... (2 Replies)
Discussion started by: hareeshram
2 Replies

6. UNIX for Dummies Questions & Answers

If ‘922’ Code does not exist on ‘03’ Record, ‘901’ Code will be there instead, move ‘03’ R

01,011600033,011600033,110516,0834,2,90,,2/ 02,011600033,011103093,1,110317,0834,,2/ 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+000000 00354,,/ 03,113806,,015,+00000559618,,,901,+00000000096,,,922,+000000 00621,,/ 88,902,+0000000025218,,/... (1 Reply)
Discussion started by: sgoud
1 Replies

7. Programming

how i prepare a c++ code(c code) for implementing my own protocol format

helo my protocol format is given below { destno,mode,no.of packet,pktsize,,pktno,textsize,CRC} description:- { is starting flag destno - 4bytes mode - 1 byte no.of pkt - 4byes pktsize - 6 bytes ... (1 Reply)
Discussion started by: amitpansuria
1 Replies
Login or Register to Ask a Question