Help with understand shell script coding


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with understand shell script coding
# 1  
Old 08-28-2014
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.

Code:
if [[ "$type" == file ]] ; then
   match=`expr "$file" : ${sourcefile}'.*'`
   if [[ $match != 0 ]] ; then
      tmp=`expr "$file" : '\(.*\)\..*'`
      if [[ ! -z "$tmp" ]] ; then
         tmp=`expr "$tmp" : '.*'`
         if [[ "$tmp" -ge $minFileName ]] ; then
            fileCount=$fileCount+1
            fileList="$fileList $file"
         else
            logInfo Skip $file Name to Short
         fi
      fi
   fi
fi


Last edited by bartus11; 08-28-2014 at 05:50 PM.. Reason: Please use [code][/code] tags.
# 2  
Old 08-29-2014
That code snippet checks if the variable type holds the string "file", if so it checks if the variable file starts with the string contained in the variable sourcefile, if so it strips what windows/DOS calls the "extension" including the dot, and then checks the length of the result; if greater or equal a defined minimum, trying (but failing) to increment the variable filecount and add the contents of the variable file to the variable filelist; if less than it logs this info somewhere.
Without way more context it's impossible to answer your question.
The connection between the variables type and file is not known, nor do I see where your *FILENAME* comes into play and what you want to achieve with it...
This User Gave Thanks to RudiC For This Post:
# 3  
Old 08-29-2014
Thank very much for your explanation RudiC,

Here is a bit more of explanation of what I am trying to do. Currently when the script is executed a file name parameter (LTRPRT*) is passed and as you mentioned, checks and makes sure the files exists and are at least the minimum length. Then it takes both of the bellow shown files and FTP them to a specified server. However, I am in need of only checking and sending one of the files. I have tried passing as a parameter
(*CIR-RISKYREM*) or (LTRPRT*CIR-REISKYREM.LTR) and both files keeps getting send over. So I figured the code I placed was the culprit and needed to be modified.

Thanks again and enjoy your day...
Code:
LTRPRT__00000001960000000001CIR-COMITMNT.LTR
LTRPRT__00000005110000000001CIR-RISKYREM.LTR

---------- Post updated at 08:57 AM ---------- Previous update was at 08:45 AM ----------

Sorry RucyC, I meant to say that when I tried to pass such parameter values, none of the files gets send over and gives me and exception error handling message saying there are no files to send.

Last edited by rbatte1; 08-29-2014 at 11:55 AM.. Reason: Added CODE tags
 
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. Shell Programming and Scripting

UNIX script coding help?

Unix script coding help? i am trying to write a code that will display following menu to user: (A) Add (B) Subtract (C) Multiply (D) Divide (E) Modulus (F) Exponentiation (G) Exit Then ask user for choice (A-F). After taking users choice ask user for two numbers and perform... (3 Replies)
Discussion started by: renegade755
3 Replies

3. 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

4. Shell Programming and Scripting

Need help in shell script coding

I have a file f1.txt that contains string: f1.txt aaa bbb ccc ... I want to write code to search that each string in file f2.txt(this file contains 1000+line codes). file f2.txt .. .. ....aaa...xyz.. ... ... ...ppp... (dots . can be characters ot blank spaces) If particular... (2 Replies)
Discussion started by: Sanchit
2 Replies

5. Shell Programming and Scripting

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. if ; then for F in $(find $DIR/. ! -name . -prune -name "DP_*.dat") do IN=${F##/*/} OUT='ORD'$(echo $IN | cut -c7-) exec.ksh $IN... (2 Replies)
Discussion started by: kam786sim
2 Replies

6. 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

7. Shell Programming and Scripting

Secure coding standards for Shell Programming

Hi, Can anyone point me to Secure coding standards for shell programming guides, links etc etc... Thanks and regards, Vamsi K Surampalli. (2 Replies)
Discussion started by: vamsisurampalli
2 Replies

8. 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

9. Shell Programming and Scripting

Coding Standard For Unix Shell Scripting!!!

Is there any site on Coding Standard for Shell Scripting in UNIX. Please help me know!!!!! Thanks Om (1 Reply)
Discussion started by: Omkumar
1 Replies

10. Shell Programming and Scripting

Shell Coding question for any experts out there

Given this one long stream of data (all one line): <TransactionDetail><TransactionHeader><ErrorLogging>YES</ErrorLogging><HistoryLogging>YES</HistoryLogging><ErrorDetection>NO</ErrorD... (4 Replies)
Discussion started by: dfran1972
4 Replies
Login or Register to Ask a Question