0

This may be a very silly question, but I currently have a script that contains some HTML content. It's easy for me to create the HTML page after running the script by doing:

./scriptName.sh > test.html

However, what I would like to achieve is for the HTML page to be created within the script, and not pass it as an argument when executing it, nor have it specified in any way from the user.

In other words, I'd like for the script to run like:

./scriptName.sh

and within that script, for the HTML to be created similar to how it would be when passed at the execution.

Is this possible? If so, how would I achieve this?

For what it's worth, my script at a very simplistic level looks something like this:

#!/bin/bash

cat << _EOF_
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<h1>Hello World</h1>

</body>
</html>

_EOF_
Adam
  • 2,384
  • 7
  • 29
  • 66

1 Answers1

6

You're already writing to the file, what you're missing is creating the file...

Something like this should work

#!/bin/bash
touch test.html

cat > test.html << EOF

<!DOCTYPE html>
<html>
  <head>
    <title>New Page</title>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

EOF

And you can change 'test.html' to whatever file name you want, along with path.

Reference: https://stackoverflow.com/a/23279682/5757893

mohkamfer
  • 435
  • 3
  • 12