LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2014, 03:48 PM   #1
MDara
LQ Newbie
 
Registered: Feb 2014
Posts: 5

Rep: Reputation: Disabled
Decoding Shell Script


I am trying to understand a shell script and
am unable to figure out what this code snippet implies:

$(set *; echo ${*/#/-a })

This is part of this line of code:
mutt ${EMAILGROUP} $(set *; echo ${*/#/-a }) -s "EMAILSUBJECT"

mutt is an email client. '-a' is the token for email attachment.

Any help is appreciated.

Thanks,
MD
 
Old 04-16-2014, 06:03 PM   #2
Luridis
Member
 
Registered: Mar 2014
Location: Texas
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616

Rep: Reputation: 167Reputation: 167
Quote:
root# set *
root# echo *

<file-names in current directory were printed>
I didn't know either, I'm going to venture a guess that # is the number of files. So, maybe the echo ${whatnot} is piping the attachments.

This is the sort of thing that really makes me nuts about shell-scripting, the ambiguity between commands, $PATH programs and builtins.

Last edited by Luridis; 04-16-2014 at 06:06 PM.
 
Old 04-16-2014, 06:39 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Actually
Code:
${*/#/-a }
is shell parameter expansion of the form
Code:
${parameter/pattern/string}
It takes each positional parameter (a.k.a. arguments) and add -a followed by a blank space at the beginning. The special character # used as pattern is an anchor. It means "at the beginning" and if used alone it is meant to mark the position before the first character so that you can simply add something there, leaving the rest untouched.

As you guessed, it is a way to add all the files in the current working directory as attachments, by preceding each name with the -a option of mutt. The set command sets positional parameters (arguments) of the current shell in order to use them as $* in the parameter substitution.

Some references:
http://www.gnu.org/software/bash/man...nal-Parameters
http://www.gnu.org/software/bash/man...eter-Expansion
http://www.gnu.org/software/bash/man...name-Expansion
http://www.gnu.org/software/bash/man...he-Set-Builtin

Please note that the asterisk * has a different meaning in the set statement above and in parameters expansion. The former is the wildcard for filename expansion, the latter is the special shell variable $* to which all the positional parameters are assigned.

Last edited by colucix; 04-16-2014 at 06:40 PM.
 
Old 04-16-2014, 06:49 PM   #4
Luridis
Member
 
Registered: Mar 2014
Location: Texas
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616

Rep: Reputation: 167Reputation: 167
I'm not 100% sure, because I don't have that installed, but this is what I gather:

mutt <destinationBox??>, all the files in the current directory beginning with a number, "-a" to signal attachments, "-s" says we have subject of "this is my subject"
 
Old 04-16-2014, 06:54 PM   #5
Luridis
Member
 
Registered: Mar 2014
Location: Texas
Distribution: LFS 9.0 Custom, Merged Usr, Linux 4.19.x
Posts: 616

Rep: Reputation: 167Reputation: 167
Oops, he beat me while I was typing that up. And I totally mucked up the anchor..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Decoding vendor-encapsulated-information in dhclient-script Rish.Ahm Linux - Networking 2 09-20-2012 03:22 AM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
FLAC decoding script jamesan Programming 5 08-05-2009 07:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration