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.
To run bash script with 2 arguments
Input file
How to change NAME and DOMAIN in input file with any arguments in content as below.
My name: NAMEOutput file with arguments default value
My Blog: https://DOMAIN.com
My name: HuuOutput file with arguments another vaule
My Blog: https://huuphan.com
My name: DevopsMy bash script
My Blog: https://devopsroles.com
$ cat arguments_file.shThe content bash script
#!/bin/bashRunning bash script with default value
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
$ ./arguments_file.shThe output as picture below:
To run bash script with 2 arguments
$ ./arguments_file.sh Devops devopsrolesThe display as picture below:
Comments
Post a Comment