Bash script arguments from a file content

In this tutorial, how to change string content of file as arguments. I written  Bash script arguments from a file content as below:
Input file
How to change NAME and DOMAIN in input file with any arguments in content as below.
My name: NAME
My Blog: https://DOMAIN.com
Output file with arguments default value
My name: Huu
My Blog: https://huuphan.com
Output file with arguments another vaule 
My name: Devops
My Blog: https://devopsroles.com
My bash script 
$ cat arguments_file.sh
The content bash script
#!/bin/bash
argument1=Huu
argument2=huuphan
INPUT=/home/huupv/scripts/input.txt
OUTPUT=/home/huupv/scripts/output.txt
RED='\033[0;31m'
NC='\033[0m' # No Color
if [ $# -eq 2 ];then
    argument1=$1
    argument2=$2
fi
sed -f - "$INPUT" > "$OUTPUT"<<EOF
    s/NAME/$argument1/g
    s/DOMAIN/$argument2/g
EOF
Running bash script with default value
$ ./arguments_file.sh
The output as picture below:

Bash script arguments from a file content

To run bash script with 2 arguments
$ ./arguments_file.sh Devops devopsroles
The display as picture below:
Bash script arguments from a file content - www.huuphan.com



Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install and configure zimbra multi server