1

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_

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

Great, this is exactly what I needed. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.