I'm making a page generator in bash. When checking for argument $2 to use as title of the page i'm generating, it finds nothing and echo the "No title supplied..." line.
Here is the snippet containing $2:
header() {
echo "<!DOCTYPE html>" > $filename.html
echo "<html>" >> $filename.html
echo "<head>" >> $filename.html
if [ -z "$2" ]; then
echo "No title supplied. Using name of the file."
echo " <title>$filename</title>" >> $filename.html
else
echo " <title>$2</title>" >> $filename.html
fi
echo " <link rel=\"stylesheet\" href=\"styles.css\">" >> $filename.html
echo "</head>" >> $filename.html
echo "<body>" >> $filename.html
echo "" >> $filename.html
}
Here is the link to the full script: https://ghostbin.co/paste/p8qpx
headeris given any arguments, let alone a 2nd argument. The function cannot see the script's positional arguments, if that is what you are referring to.$filename.html:{ echo ...; echo ...; ...; } > $filename.html. The "no title supplied" line should be written to standard error (echo "No title..." >&2).