<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: basic scripting in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058711#M94459</link>
    <description>Try this...&lt;BR /&gt;&lt;BR /&gt;for i in `cat filename`&lt;BR /&gt;do&lt;BR /&gt;  cp ${i} ${i}.old&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;That should do it.</description>
    <pubDate>Wed, 22 Aug 2007 12:44:16 GMT</pubDate>
    <dc:creator>Keith Johnson</dc:creator>
    <dc:date>2007-08-22T12:44:16Z</dc:date>
    <item>
      <title>basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058710#M94458</link>
      <description>i need help with a basic loop. for some reason the syntax is eluding me. im creating a list of filenames appended into a file. i want to run an operation against the names in the file. for example...&lt;BR /&gt;&lt;BR /&gt;file contents:&lt;BR /&gt;&lt;BR /&gt;flie1&lt;BR /&gt;file2&lt;BR /&gt;file3&lt;BR /&gt;&lt;BR /&gt;i want to create the for loop as follows - &lt;BR /&gt;&lt;BR /&gt;for i in `cat filename` do&lt;BR /&gt;&lt;BR /&gt;cp file1 file1.old&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;i want to perform this task on all filenames in the file then exit when complete. &lt;BR /&gt;&lt;BR /&gt;i've written things like this many times, but its been so long im having trouble setting up the structure to run an operation against a file list. &lt;BR /&gt;&lt;BR /&gt;Please help.</description>
      <pubDate>Wed, 22 Aug 2007 12:38:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058710#M94458</guid>
      <dc:creator>CRollins</dc:creator>
      <dc:date>2007-08-22T12:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058711#M94459</link>
      <description>Try this...&lt;BR /&gt;&lt;BR /&gt;for i in `cat filename`&lt;BR /&gt;do&lt;BR /&gt;  cp ${i} ${i}.old&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;That should do it.</description>
      <pubDate>Wed, 22 Aug 2007 12:44:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058711#M94459</guid>
      <dc:creator>Keith Johnson</dc:creator>
      <dc:date>2007-08-22T12:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058712#M94460</link>
      <description>&lt;!--!*#--&gt;for i in `cat filename`&lt;BR /&gt;do&lt;BR /&gt;    cp $i $i.old&lt;BR /&gt;done</description>
      <pubDate>Wed, 22 Aug 2007 12:44:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058712#M94460</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-08-22T12:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058713#M94461</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;First, *don't* use 'for i in `cat file` do:&lt;BR /&gt;&lt;BR /&gt;You don't need to spawn a process to read, let the shell do it:&lt;BR /&gt;&lt;BR /&gt;while read FILE do&lt;BR /&gt;    cp ${FILE} ${FILE}.old&lt;BR /&gt;done &amp;lt; filenames&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Aug 2007 12:44:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058713#M94461</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-22T12:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058714#M94462</link>
      <description>do i need an exit at the end?</description>
      <pubDate>Wed, 22 Aug 2007 13:15:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058714#M94462</guid>
      <dc:creator>CRollins</dc:creator>
      <dc:date>2007-08-22T13:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058715#M94463</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; do i need an exit at the end?&lt;BR /&gt;&lt;BR /&gt;It's not necessary.  The exit value will be that of the last command.  You could do:&lt;BR /&gt;&lt;BR /&gt;while read FILE do&lt;BR /&gt;  cp ${FILE} ${FILE}.old&lt;BR /&gt;  STATUS=$?&lt;BR /&gt;  if [ "${STATUS}" -ne 0 ]; then&lt;BR /&gt;      echo "Error: Copy of ${FILE} failed"&lt;BR /&gt;      exit 1&lt;BR /&gt;  fi&lt;BR /&gt;done &amp;lt; filenames&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Aug 2007 13:23:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058715#M94463</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-22T13:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058716#M94464</link>
      <description>what is filenames? Is the list? how do i print it into done?</description>
      <pubDate>Wed, 22 Aug 2007 13:35:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058716#M94464</guid>
      <dc:creator>CRollins</dc:creator>
      <dc:date>2007-08-22T13:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058717#M94465</link>
      <description>Hi (agani):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; what is filenames? Is the list? how do i print it into done?&lt;BR /&gt;&lt;BR /&gt;"filenames" is a file that contains the *names* of the files to be copied, one filename per line.&lt;BR /&gt;&lt;BR /&gt;# cat filenames&lt;BR /&gt;file1&lt;BR /&gt;file2&lt;BR /&gt;file3&lt;BR /&gt;&lt;BR /&gt;The "&amp;lt; filenames" notation means to read each line of 'filenames'.  The 'while read FILE' means read each line of the input file into the variable named 'FILE'.&lt;BR /&gt;&lt;BR /&gt;This avoids spawning a 'cat' process to create a list of names (lines) that your original 'for' loop iterated over.  In my code, the 'FILE' variable holds the filename.  In yours, the 'i' variable did the same.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Aug 2007 13:43:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058717#M94465</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-22T13:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058718#M94466</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;By the way, welcome to the ITRC Forums!  When you are satisfied with the help you have been offered, please read and give consideration to:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://forums1.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;https://forums1.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 22 Aug 2007 14:23:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058718#M94466</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-22T14:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058719#M94467</link>
      <description>&lt;!--!*#--&gt;You can also avoid the cat like so:&lt;BR /&gt;&lt;BR /&gt;for i in $(&amp;lt; /filename )&lt;BR /&gt;do&lt;BR /&gt; cp -p ${i} ${i}.old&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Aug 2007 14:57:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058719#M94467</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2007-08-22T14:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: basic scripting</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058720#M94468</link>
      <description>&amp;gt;Geoff: You can also avoid the cat like so:&lt;BR /&gt;for i in $(&amp;lt; /filename )&lt;BR /&gt;&lt;BR /&gt;You beat me.  :-)&lt;BR /&gt;&lt;BR /&gt;The difference between $(&amp;lt; file) and while read is that the former allows multiple files per line (delimited by whitespace but read doesn't.  Also while read will allow an infinite number of files but $(&amp;lt;) won't.</description>
      <pubDate>Thu, 23 Aug 2007 04:04:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-scripting/m-p/4058720#M94468</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-08-23T04:04:58Z</dc:date>
    </item>
  </channel>
</rss>

