<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>FileCreation &amp;mdash; Paul Sutton</title>
    <link>https://personaljournal.ca/paulsutton/tag:FileCreation</link>
    <description>Personal Blog</description>
    <pubDate>Tue, 26 May 2026 22:17:45 +0000</pubDate>
    <item>
      <title>Bash scripting 2 - files</title>
      <link>https://personaljournal.ca/paulsutton/bash-scripting-2-files</link>
      <description>&lt;![CDATA[Bash scripting 2 - files&#xA;&#xA;In between getting my head around rust,   I am doing more with bash. &#xA;&#xA;The following script is based on the iso download script, but creates 3 empty text files&#xA;&#xA;!/bin/bash&#xA;echo Create files listed in an array with the touch command&#xA;files=(&#xA;  # list of files to create&#xA;  &#34;file1.txt&#34;&#xA;  &#34;file2.txt&#34;&#xA;  &#34;file3.txt&#34;&#xA;)&#xA;&#xA;Loop to create each file&#xA;for filelist in &#34;${files[@]}&#34;; do&#xA;  touch &#34;$filelist&#34;&#xA;done&#xA;&#xA;list files&#xA;ls -l&#xA;&#xA;Which is good for creating lots of files of the same type. Now letgs say we would like to add some text to each of the files&#xA;&#xA;we can amend the script as follows&#xA;&#xA;Loop to append each file&#xA;for filelist in &#34;${files[@]}&#34;; do&#xA;  touch &#34;$filelist&#34; # create the files&#xA;  lorem   &#34;$filelist&#34; # add lorem text to each file&#xA;  #lorem     &#34;$filelist&#34; # append lorem text to each file &#xA;done&#xA;&#xA;list files&#xA;ls -l&#xA;&#xA;You will need access to the lorem command, which can be installed on a Debian based system using&#xA;&#xA;sudo apt install libtext-lorem-perl&#xA;&#xA;Please see the stackoverflow post&#xA;&#xA;Also see the man page for lorem&#xA;&#xA;man lorem&#xA;You will, of course need to set the execute permissions&#xA;chmod +x script.sh&#xA;&#xA;Tags&#xA;&#xA;#Bash,#Bashscripting,#FileCreation&#xA;&#xA;hr&#xD;&#xA;&#xD;&#xA;table&#xD;&#xA;thead&#xD;&#xA;trtda rel=&#34;me&#34; href=&#34;https://qoto.org/@zleap&#34;Mastodon/a/td&#xD;&#xA;tda href=&#34;https://wiki.ircnow.org/?n=Shelllabs.Intro&#34;ShellLabs/td&#xD;&#xA;tda href=&#34;https://joinmastodon.org/&#34;Join Mastodon/a/td/tr/thead/table&#xD;&#xA;center&#xD;&#xA;AI statement : b Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity.  Consent CANNOT be assumed, it has to be granted. /b&#xD;&#xA;/center&#xD;&#xA;&#xD;&#xA;a href=&#34;https://liberapay.com/PaulSutton/donate&#34;img alt=&#34;Donate using Liberapay&#34; src=&#34;https://liberapay.com/assets/widgets/donate.svg&#34;/a&#xD;&#xA;]]&gt;</description>
      <content:encoded><![CDATA[<p>Bash scripting 2 – files</p>

<p>In between getting my head around rust,   I am doing more with bash.</p>

<p>The following script is based on the iso download script, but creates 3 empty text files</p>

<pre><code class="language-bash">#!/bin/bash
echo Create files listed in an array with the touch command
files=(
  # list of files to create
  &#34;file1.txt&#34;
  &#34;file2.txt&#34;
  &#34;file3.txt&#34;
)

# Loop to create each file
for filelist in &#34;${files[@]}&#34;; do
  touch &#34;$filelist&#34;
done

#list files
ls -l
</code></pre>

<p>Which is good for creating lots of files of the same type. Now letgs say we would like to add some text to each of the files</p>

<p>we can amend the script as follows</p>

<pre><code class="language-bash"># Loop to append each file
for filelist in &#34;${files[@]}&#34;; do
  touch &#34;$filelist&#34; # create the files
  lorem &gt; &#34;$filelist&#34; # add lorem text to each file
  #lorem &gt;&gt; &#34;$filelist&#34; # append lorem text to each file 
done

#list files
ls -l

</code></pre>

<p>You will need access to the lorem command, which can be installed on a Debian based system using</p>

<pre><code class="language-bash">sudo apt install libtext-lorem-perl
</code></pre>

<p>Please see the <a href="https://unix.stackexchange.com/questions/97160/is-there-something-like-a-lorem-ipsum-generator" rel="nofollow">stackoverflow post</a></p>

<p>Also see the man page for lorem</p>

<pre><code class="language-bash">man lorem
</code></pre>

<p>You will, of course need to set the execute permissions</p>

<pre><code class="language-bash">chmod +x script.sh
</code></pre>

<p><strong>Tags</strong></p>

<p><a href="/paulsutton/tag:Bash" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Bash</span></a>,<a href="/paulsutton/tag:Bashscripting" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">Bashscripting</span></a>,<a href="/paulsutton/tag:FileCreation" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">FileCreation</span></a></p>

<hr>

<p><table>
<thead>
<tr><td><a href="https://qoto.org/@zleap" rel="nofollow">Mastodon</a></td>
<td><a href="https://wiki.ircnow.org/?n=Shelllabs.Intro" rel="nofollow">ShellLabs</td>
<td><a href="https://joinmastodon.org/" rel="nofollow">Join Mastodon</a></td></tr></thead></table>

AI statement : <b> Consent is NOT granted to use the content of this blog for the purposes of AI training or similar activity.  Consent CANNOT be assumed, it has to be granted. </b>
</p>

<p><a href="https://liberapay.com/PaulSutton/donate" rel="nofollow"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg"></a></p>
]]></content:encoded>
      <guid>https://personaljournal.ca/paulsutton/bash-scripting-2-files</guid>
      <pubDate>Wed, 25 Dec 2024 13:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>