0

I want to make automatically fill the text file that I made but I don't know how, I want to make a .sh script to work automatically but I don't know how. the script that I have thought of for example like this

touch " ubuntu story "

after this I want to fill in the text in my story file, for example the text you want to add like this

Ubuntu is one of the most secure operating systems around. And the long-term support releases give you five years of security patches and updates.

Developer = Canonical Ltd.
OS family = Linux
Working state = Current
Source model = Open-source[1][2]
Initial release = 20 October 2004 (15 years ago)

how to addin this text to file ubuntu story with script ?

if using the manual method I can use this method

nano "ubuntu story"

after that I paste in the terminal column, then I Ctrl + X + Y + Enter, after that it will be saved.

please help me if you use the bash .sh script

0

You can use a here document

#!/bin/bash

cat > "ubuntu story" <<\EOF
Ubuntu is one of the most secure operating systems around. And the long-term support releases give you five years of security patches and updates.

Developer = Canonical Ltd.
OS family = Linux
Working state = Current
Source model = Open-source[1][2]
Initial release = 20 October 2004 (15 years ago)
EOF

Quoting of any part of the word EOF either as \EOF or 'EOF' for example prevents shell expansion of the contents.

I used a bash shebang since that's what you tagged your question, but here documents are supported in all POSIX shells.

  • great, it work, thanks – Joe Cola Jun 2 '20 at 2:37
0

In some of my scripts I do something like this:

touch ~/Templates/"untitled_document"


LOG=/var/log/backup.log
echo "* $(date -R) *" >> $LOG

Or:

fname=/etc/fstab
str1="# Entry for /dev/sdb6 :"
echo $str1 >> $fname

Note that one > overwrites or creates new file and >> adds to end of file. I have additional data I add to log file. Also better with Linux to use CamelCase, under_score or justonename rather than spaces. You have to escape spaces in future commands which makes it more complicated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.