1

I have written the below script to automate email notification.

#!/bin/bash

TO_ADDRESS="pratik@gmail.com"
FROM_ADDRESS="Pratik@example.com"
SUBJECT="November 2016 Step"
BODY="Hi All,\n\n Product Mapping Check is done.\n\n Regards, \n\n Pratik"
echo ${BODY}| mail -s ${SUBJECT} ${TO_ADDRESS} -- -r ${FROM_ADDRESS}

Requirement : A unix script when executed should send an email from Pratik@example.com to Pratik@gmail.com with above subject and body. When the script is run it should ask for month year parameter. For example register.sh is the script name. the run command should look like

> register.sh November 2016

When the above script is executed, it should take the month and year input and copy it to the subject line . Then send out the email.

Let me know if i need to config anything or call any server details in the script.

jww
  • 97,681
  • 90
  • 411
  • 885
Pratik Fouzdar
  • 29
  • 1
  • 2
  • 7
  • [How do I parse command line arguments in Bash?](https://stackoverflow.com/q/192249/608639), [Accessing bash command line args $@ vs $*](https://stackoverflow.com/q/12314451/608639), [Best way to parse command line args in Bash?](https://stackoverflow.com/q/14786984/608639), [Pass command line arguments to bash script](https://unix.stackexchange.com/q/32290/56041), [Passing command line arguments through Bash](https://stackoverflow.com/q/25467253/608639), etc. – jww Apr 19 '18 at 08:49
  • Possible duplicate of [In Bash, how do you access command line arguments inside a function?](https://stackoverflow.com/questions/2740906/in-bash-how-do-you-access-command-line-arguments-inside-a-function) – jww Apr 19 '18 at 08:50

2 Answers2

0

You can use the shell's positional parameters, $1, $2, ... to refer to arguments of your script:

SUBJECT="$1 $2 Step"

With register.sh November 2016 this makes $1 contain November and $2 contain 2016.

Jens
  • 69,818
  • 15
  • 125
  • 179
0

The shell script is having a concept of runtime arguments which can be added by the below command

$1, $2 etc

$1 is the first argument $2 is the second argument from runtime