1

I am trying to write a shell script for which 1st 2nd and 3rd...n argument contains multiple words

MAILING_LIST="abc@gmail.com xyz@gmail.com zed@gmail.com"
echo $MAILING_LIST
mailing "Error in Job"  " There were some records that couldn't be loaded into DB" " " $MAILING_LIST

Now i only want to print my mailing list in the function so that i can use that to send the email

obviously no of mails in mailing list can change and so forth .

Kindly help me with this issue.

P.S if i use echo $# it gives me no of args as 6 now my requirement is to print/get the mailing list only in my function ..

Rajendra_Prasad
  • 1,300
  • 4
  • 18
  • 36
Sunil
  • 13
  • 4

1 Answers1

2

Enclose the variable in quotes, since arguments are separated with spaces:

echo "$MAILING_LIST"
mailing "Error in Job"  " There were some records that couldn't be loaded into DB" " " "$MAILING_LIST"

Just like you did with "Error in Job". If you had left those quotes out, there would have been eight arguments.

Tim
  • 13,904
  • 10
  • 69
  • 101
  • It does not solve my issue ... my question is to wap that will get only emails in the specified function... if you would provide me with a similar sample that would be of great help.. – Sunil May 21 '13 at 09:26
  • Sorry, I don't understand your question. – Tim May 21 '13 at 10:44
  • I have a function which gets some n input arguments comprising of 2 or more words each ... now it will be always the case that i don't have to consider the first four arguments (say comprising of 20 words total ) my requirement is to only get the mail id's so i can send them the mail . In the function i don't want to consider the first four arguments and only consider the email id's that can be the last argument how can i achieve that in the programme. as i'm not able to achieve that using for /while /awk . – Sunil May 21 '13 at 11:05
  • Do you want to split a space-separated string? – Tim May 21 '13 at 11:25
  • @Sunil Here is one such SO question: [How do I split a string on a delimiter in bash?](http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash). – Tim May 21 '13 at 11:37