Understanding bash code


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Understanding bash code
# 1  
Old 11-17-2014
Understanding bash code

I am not able to understand below line in unix bash shell.Could anyone explain what it will do
Code:
result="${path1}/*${var1}*${var2}*wssreligibleitem*.csv"

path1 is defined and it is a directory path
var1 is defined and it holds string value like abc
var2 is defined and it holds string value like cde
Basically i did not understand the importance of /* and * .I have highlight in bolt

Last edited by Corona688; 11-17-2014 at 12:54 PM..
# 2  
Old 11-17-2014
What happens if you echothat?
Code:
echo ${path1}/*${path2}*${var1}*wssreligibleitem*.csv

# 3  
Old 11-17-2014
Quote:
Originally Posted by vamsi.valiveti
I am not able to understand below line in unix bash shell.Could anyone explain what it will do
Code:
result="${path1}/*${path2}*${var1}*wssreligibleitem*.csv"

path1 is defined and it is a directory path
path1 is defined and it is a directory path
var1 is defined and it holds string value
Basically i did not understand the importance of /*,*



Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks
It is nice that you told us (twice) that $path1 expands to a directory path. It would be nice if you told us how path2 is defined. I don't understand why you're saying that you do not understand the importance of /*,* since that string does not appear anywhere in the assignment statement you showed us???

Presumably after you go to the effort to define the variable result you use it somewhere later in your code. How is it used?

The echo RudiC suggested might not help much since the string is quoted in the definition and unquoted in the echo.
# 4  
Old 11-17-2014
@Don Cragun


I have done some changes in my orginal post and could you please clarify now

In the script we are using in a loop `ls $result`
# 5  
Old 11-17-2014
And you have your answer:
What is the output of:
Code:
 ls $result

# 6  
Old 11-17-2014
Or, for that matter, echo $result
# 7  
Old 11-17-2014
The filename matching pattern /* matches a literal / character in a pathname followed by any string of zero or more characters other than / except that the * will not match a period (.) if it is the first character in a pathname or the first character following a / in a pathname.

The filename matching pattern * any matches any string of zero or more characters other than / except that the * will not match a period (.) if it is the first character in a pathname or the first character following a / in a pathname.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Understanding the difference between individual BASH login scripts

Hello... and thanks in advance for reading this or offering me any assistance I'm trying to understand specific differences between the various login scripts... I understand the differences between interactive vs non-interactive and login vs non-login shells... and that's not where my question... (4 Replies)
Discussion started by: bodisha
4 Replies

2. Programming

Understanding Assembly Code

As the title suggests, I want to better understand the following assembly code: section .text global main ; must be declared for linker (gcc) main: ; tell linker entry point mov edx, len ; message length mov ecx, msg ; message to write... (2 Replies)
Discussion started by: Azrael
2 Replies

3. Shell Programming and Scripting

Help with perl code understanding

Hi, I need to understand below perl code, can some one advise me. perl -MDate::Parse -e'BEGIN{$main::now=time;$main::old=(time-60*30)}' -nE'if(/^(\w+\s+\d+\s+\d+:\d+:\d+)/) {$t=str2time $1; $t > $old && $t < $now && print}' (1 Reply)
Discussion started by: learnbash
1 Replies

4. Programming

Understanding perl code

What is the difference between the two statements below? A: $a->{"$fruit"}->{"$color"}->{size} = $size B: $size = $a->{"$fruit"}->{"$color"}->{size} Please assist. Thanks! (0 Replies)
Discussion started by: onlinelearner02
0 Replies

5. Shell Programming and Scripting

Help understanding Perl code.

Well, I found myself trying to fix some Perl code (Ive never done any Perl in my life) and I pinpointed the place where the bug could be. But to be sure I have to know what does a few line of code mean: $files_lim =~ (/^\d*$/) $files_lim =~ (/^\d*h$/)$files_age =~ s/h//The code where this was... (0 Replies)
Discussion started by: RedSpyder
0 Replies

6. UNIX for Dummies Questions & Answers

Help understanding a simple command in BASH

This is the command. Assume file1 exists but file2 does not: ls file1 file2 >newfile 2>&1 This simply makes a text file with two lines: file1 \n file2 could not be found. What I don't understand is that when you run this command: ls file1 file2 >newfile, it prints "file2 could not be found" to... (1 Reply)
Discussion started by: phunkypants
1 Replies

7. UNIX Desktop Questions & Answers

Understanding the code

hello all, May i know what is this "DEBUG_ME $DEBUG_CMD main" doing in the below code. I am confused with alias also "alias DEBUG_ME='#'". Thanks for your help. set -x alias DEBUG_ME='#' if ; then . /product/apps/informatica/v7/pc/ExtProc/debug.ksh "$1" fi # Declaring the... (1 Reply)
Discussion started by: Ariean
1 Replies

8. Shell Programming and Scripting

Problems understanding example code

I am really new to UNIX and programming in general and so apologies if this thread is a bit simple. I have searched and found a piece of sample code for a training program I am currently undertaking, but seeing as I am relatively new, I dont completely understand how it works. Here is the... (1 Reply)
Discussion started by: Makaer
1 Replies

9. Shell Programming and Scripting

Need help in understanding thisperl code.

Can any body explains the under given lines of code i have difficulties in understanding it, my $errorlog = "/var/log/controler.log"; &initLanguage($language); &launchCbox(); sub launchCbox { ... (1 Reply)
Discussion started by: Raheel Hassan
1 Replies

10. UNIX for Dummies Questions & Answers

Little Trouble Understanding some code...

Couple of questions as I try to decipher someones code who left... What would something coded like this do? IFS=: grep FIELD1 /Path/Path2/Param.fle | read LBL1 LBL2 USRID EADR SUBJ SERVERNAME CFGTBL DIR ERR=0 Param.fle contents.. FIELD1:FEI::FIELD2:dATAFIELD BATCH:MAIN SERVER......etc.. (2 Replies)
Discussion started by: NycUnxer
2 Replies
Login or Register to Ask a Question

Featured Tech Videos