Understand a old unix shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Understand a old unix shell script
# 1  
Old 02-10-2011
Understand a old unix shell script

Hi All,
I have a unix old script i but i am not able to understand the few commands in it and what it does. below is the script.
Code:
 if [ -f /ITF_*.dat ];
  then 
     for F in $(find $DIR/. ! -name . -prune -name "DP_*.dat")  
    do
     IN=${F##/*/}
     OUT='ORD'$(echo $IN | cut -c7-)
    exec.ksh $IN $OUT
     if [ $? -ne 0 ]; then
       exit 1
     fi
   done

I am not able to understand what does this script code part does and also what does the below command does.
1. if [ -f /ITF_*.dat ];
2. IN=${F##/*/}

Can you please let me know.
# 2  
Old 02-10-2011
1. if any files exist that match ITF_*.dat in the root (/) directory.
2. For an absolute path (one beginning with /), will remove the path, leaving just the filename. i.e. removes everything (*) starting from / and ending in /)

Code:
${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.

test man page
bash man page (search for Parameter Expansion)
This User Gave Thanks to Scott For This Post:
# 3  
Old 02-10-2011
1) Is testing whether there is at least on file (-f) in the root directory "/" which matches the pattern "ITF_*.dat". The asterisk is a wild card and the underscore and full stop characters are part of the name of the file.

2) Is doing the same as the "basename" unix command on the filename in parameter $F . It is removing any leading path information to leave the name of the file only.
This is a Shell function. Just search your Shell manual for the string "##" to read about it.
This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help to understand the below shell script

Please help me to understand the below 3 lines of code.execute shell in jenkins 1)APP_IP=$( docker inspect --format '{{ .NetworkSettings.Networks.'"$DOCKER_NETWORK_NAME"'.IPAddress }}' ${PROJECT_NAME_KEY}"-CI" ) 2)HOST_WORKSPACE=$(echo ${WORKSPACE} | sed... (1 Reply)
Discussion started by: naresh85
1 Replies

2. UNIX for Dummies Questions & Answers

How to Understand file writing in Progress in UNIX?

Hi All, I have a requirement, where i have to pool file A data to file B continuously and need to process the data in the file B. Since the data need to be processed only once so i have to truncate the data in file A after every pool. So that on the next pooling i can get the fresh data and... (3 Replies)
Discussion started by: mayank2211
3 Replies

3. UNIX for Dummies Questions & Answers

Help with understand shell script coding

Good afternoon everyone, I am very new to UNIX shell scripting and I am trying to understand the following code. I know what it does but I need to modify it so it will allow me to pass a file name as *FILENAME* Thank for any guidance offered. if ] ; then match=`expr "$file" :... (2 Replies)
Discussion started by: Walter Barona
2 Replies

4. Red Hat

How to Understand the UNIX Time Format?

How to understand the unix time format as here i have pasted this is a unix time 1402565420 and its 3:00 PM here but its give this Output as long number How can i make it to understand format as i have 3:00 PM Normal time format <----3:00PM = 1402565420----> Unix Time Will Any one Explain to... (4 Replies)
Discussion started by: babinlonston
4 Replies

5. UNIX for Dummies Questions & Answers

Need to understand shell script

Hello, Can someone please help me understand the shell script below for installing Jboss EAP 6? It is from jboss-as-standalone.sh, what does the highlighted code mean? # Load Java configuration. && . /etc/java/java.conf export JAVA_HOME Thanks! (4 Replies)
Discussion started by: learnix
4 Replies

6. Shell Programming and Scripting

Need to understand a couple of Shell Logic

Hi, I am trying what the following loop does : for i in XYZ do for j in M1 R1 R2 R3 do if then kList="" n=1 while do kList="$kList $n" let n++ done There are a couple of loop as mentioned above for R1.R2.R3. (1 Reply)
Discussion started by: johnprince1980
1 Replies

7. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

8. UNIX for Dummies Questions & Answers

trying to understand rationale of unix stream i/o concept

I am an entry level programmer with no formal training in computer science. I am trying to enhance my conceptual knowledge about operating systems in general. I have been using the C programming language on Linux systems for some time and have used the traditional unix stream I/O APIs. The... (1 Reply)
Discussion started by: kaychau
1 Replies

9. UNIX for Dummies Questions & Answers

Help required to understand a variable in shell script!!!

Hi, I need to understand the following script: a=`dirname $0` b=`uname -s` if ; then c=$a/../../../platforms/$b/extlib else c=`pwd`/$a/../../../platforms/$b/extlib fi There are a bunch of variable assignments going on here!!! What does this variable means: "${a:0:1}" ... (2 Replies)
Discussion started by: abhishek2301
2 Replies

10. UNIX for Advanced & Expert Users

don't understand the unix script

if {"$my_ext_type" = MAIN]; then cd $v_sc_dir Filex.SH $v_so_dir\/$v_fr_file Can somebody tell me what does this suggest. I am pretty new to unix and I am getting confused. What i understood from here is If we have a file extension name as MAIN which we have then we change the directory to... (1 Reply)
Discussion started by: pochaman
1 Replies
Login or Register to Ask a Question