What is the meaning of ## in UNIX shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is the meaning of ## in UNIX shell script?
# 1  
Old 12-30-2016
What is the meaning of ## in UNIX shell script?

Hi All,

I am new to unix shell scripting and I was documenting one of the unix script and encountered below statements -

Code:
for ii in `ls -1rt /oracle/admin/MARSCOPY/ext_files/fpm-ifpm/*.small.txt | tail -1 | awk '{print $1}'`
do
smallssim=${ii##/oracle/admin/MARSCOPY/ext_files/fpm-ifpm/}
prefix=`echo $smallssim | awk -F. '{print $1}'`

I tried to find the meaning of ## on google or other posts but could not find it.

Can anyone please help me understand meaning of the value smallssim?

Thanks in Advance.
Jay Shukla


Moderator's Comments:
Mod Comment Please use CODE/ICODE tags correctly as required by forum rules!

Last edited by RudiC; 12-30-2016 at 03:17 PM.. Reason: Changed CODE tags.
# 2  
Old 12-30-2016
Hello shuklajayb4,

Welcome to forums, hope you will enjoy learning here. It is called Parameter expansion, when you do a man bash you could see the following.
Quote:
${parameter##word}
Remove matching prefix pattern. 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 pat-
tern (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 expansion 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.
Here is an example of same too.
So let's say we have following string into a variable.
Code:
MYSTRING="Be liberal in what you accept, and conservative in what you send"

So here is the use of # and ##.
Code:
${MYSTRING#* }	Be liberal in what you accept, and conservative in what you send
${MYSTRING##* }	Be liberal in what you accept, and conservative in what you send

As you could see above(selected text will not be shown) # is removing the text till very first space and on other hand ## is printing the text till very last(maximum) match of space. I hope this helps you.

Thanks,
R. Singh
These 2 Users Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 12-30-2016
Thanks Ravinder !! This helps to understand it better.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Meaning of =~ in shell script

Please let me understand the meaning of following line in unix bash scripting .is =~ means not equal to or equal to . if ]; then echo -e "pmcmd startworkflow -sv ${INTSERV} -d ${INFA_DEFAULT_DOMAIN} -uv INFA_DEFAULT_DOMAIN_USER" \ "-pv INFA_DEFAULT_DOMAIN_PASSWORD -usdv... (2 Replies)
Discussion started by: harry00514
2 Replies

2. UNIX for Dummies Questions & Answers

UNIX Script - snipet meaning?

What would the below code snippet mean? my ($_configParam, $_paramValue) = split(/\s*=\s*/, $_, 2); $configParamHash{$_configParam} = $_paramValue; (2 Replies)
Discussion started by: MaKha
2 Replies

3. Linux

Shell ${1:-/etc/hosts} meaning

Hello. In some script, I saw: filename=${1:-/etc/hosts} if && ; then md5sum $filename else echo “$filename can not be processed” fi # Show the file if possible ls -ld $filename 2>/dev/null What does the first line means? In $filename I still got /etc/hosts. (2 Replies)
Discussion started by: lozicd3
2 Replies

4. Shell Programming and Scripting

Meaning of each term in stty -a in unix

Hi, Can someone help me with the meaning of each term in the below command in unix: stty-aRegds, I have searched google for a lot for this, but didnt get any success in this. Kunwar (2 Replies)
Discussion started by: kunwar
2 Replies

5. Shell Programming and Scripting

Meaning of '$#' in Unix

All, In the below mentioned piece of code : if test $# -eq 1 then echo "Input parameter passed into DMI_weekly.ksh..." | tee -a $RUNLOG typeset -u ORACLE_SID export ORACLE_SID="$1" else echo "ERROR 060: Arguments passed... (3 Replies)
Discussion started by: Oracle_User
3 Replies

6. Shell Programming and Scripting

meaning of & in sh shell

All, I have a line in my code like below , could any one please tell me what this actually mean what is the & doding there. I am in sh shell #!/bin/sh .............. mv &fname &III.tar.gz Thanks in Advance, Arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

7. UNIX for Dummies Questions & Answers

meaning of .& in shell

Hi , can anyone explain me the meaning of following line ". &13FNAME/version_encours/cfg/dfm.cfg" Regards (1 Reply)
Discussion started by: scorpio
1 Replies

8. UNIX for Dummies Questions & Answers

Oot: Level 2 Unix Support? meaning

Hi all, I am sorry, I know this is not correct forum/silly question (usually this is requirement in some vacancies), but i hope someone can explain to me, what is the meaning of : SUN Tier 3 Support Tier 3 Application Installation Level 2 Solaris Level 2 AD MOM + DBA Thank you. (0 Replies)
Discussion started by: blesets
0 Replies

9. UNIX for Dummies Questions & Answers

Meaning of ; in UNIX file?

Hello. I'm looking at a file that has a ; at the beginning of certain lines. Could someone please tell me what that means? Is it a comment? Is it an execute? Thank You (1 Reply)
Discussion started by: willdaw3
1 Replies

10. UNIX for Dummies Questions & Answers

Meaning of unix-rt ldp file type

Hello I was wondering what this file type means... assuming it is some type of data. Is ldp - Linux Doc Program? What type of program would be used to read or interpret this file type? As you can see I'm not a developer, and don't review these types of files. But would like to view... (1 Reply)
Discussion started by: jfmrts
1 Replies
Login or Register to Ask a Question