I have found something similar on here but not exactly what I am looking for.
I am essentially trying to automate the creation of an nginx file which may have multiple domains attached to it.
My input looks like this:
./setup.sh domain1.com domain2.com domain3.com domain4.com domain5.com
What I am trying to do:
- Prepend
www.to each of the input domain names (on the same line) - Output all of it to a file.
Currently this breaks:
SERVER_HOSTNAME=${1}
shift
SERVER_DOMAINS=(${@})
echo '
server {
listen 80;
listen [::]:80;
root /var/www/${1}/html;
index index.html index.php index.htm index.nginx-debian.html;
server_name ${@} '
for i in "${@}"; do echo "www.${i}"; done
echo '
more lines here.
more
more
more
' > output.text
Currently this loop kind of works except it puts the www.$@ on separate lines and only outputs the 2nd part of the echo statement to the file.
Any ideas?
echos, one for the header, one for the inside content, and one for the footer? That's more efficient than what a lot of the answers are telling you to do (creating a subshell during heredoc invocation); those answers will work, but they do so at a performance penalty.{ echo "first"; for item in "$@"; do echo "second $item"; done; echo "$last"; } >output.text-- so the need to use>doesn't force you to make it all oneecho.