#! /bin/bash template="./pages/template.html" output_directory="./website/" cut_whitespace() { ws="${line%%[![:space:]]*}" # get whitespace and store to ws line="${line#"$ws"}" # remove whitespace from line } pages=() while IFS= read -r line; do pages+=("$line") done < "pages.txt" for page in "${pages[@]}"; do page_content=() output= while IFS= read -r line; do page_content+=("$line\n") done < "./pages/$page" while IFS= read -r line; do cut_whitespace if [[ "$line" == "<!--TITLE-->" ]]; then line="$ws${page_content[0]}" unset 'page_content[0]' page_content=("${page_content[@]}") elif [[ "$line" == "" ]]; then line="$ws${page_content[0]}" unset 'page_content[0]' page_content=("${page_content[@]}") elif [[ "$line" == "" ]]; then line= for content_line in "${page_content[@]}"; do line+="$content_line" done else line="$ws$line\n" fi output+="$line" done < "$template" echo "built $page..." echo -e "$output" > "$output_directory$page" done