I would like to overwrite a Django/app/settings.py text file using the Linux terminal command printf.
The settings.py starts with docstrings comments, i.e. """some text""".
With printf the format is printf'some text' > filename.txt or printf"some text" > filename.txt.
Whichever " or ' is used the subsequent occurrence of the " or ' closes printf statement and breaks the desired run of the script.
For instance,
printf'
"""
Django settings for hello_django project.
Generated by 'django-admin startproject' using Django 4.2.13.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
from pathlib import Path
' > app/hello_django/settings.py
The echo command returns the same unsuccessful result.
Is it possible to achieve what I want using the printf or echo methods?
Some useful links with pointers that I have tried, write to file with echo/printf, How do I echo a lot of content in a bash script? and How to echo a bang!
printfexpects. You need a space afterprintfand before anything else. What you are showing is one huge command, so I would expect you to get a "no such command" error. Is that not what is happening?'quoted'argument toprintf, but the text itself contains quotes (apostrophe characters). You must replace these with the sequence'\''. Close quote, backslash-quote, reopen quote. Or else, use a here-document.