<?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: Shell script problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468988#M16280</link>
    <description>Hello Barry,&lt;BR /&gt;&lt;BR /&gt;The problem with your script is that you are trying to test $i from your current directory.  You must put in the full path name in the if statement for it to work.&lt;BR /&gt;&lt;BR /&gt;Using Frederic's example (use single brackets), the if statement should read&lt;BR /&gt;&lt;BR /&gt;if [ -s "/users/admin/output/$i" ]&lt;BR /&gt;&lt;BR /&gt;You can also cd to /users/admin/output before doing the for loop.  This would allow you to remove the full path from the if statement.  Hope this helps.&lt;BR /&gt;&lt;BR /&gt;Josef</description>
    <pubDate>Thu, 30 Nov 2000 17:40:41 GMT</pubDate>
    <dc:creator>Josef Nordtome</dc:creator>
    <dc:date>2000-11-30T17:40:41Z</dc:date>
    <item>
      <title>Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468982#M16274</link>
      <description>Hi all,&lt;BR /&gt;I'm trying to write a script that checks a directory, moves the files that contain data and deletes the remaining 0 length files - Below is my script that doesn't work properly:&lt;BR /&gt;&lt;BR /&gt;for i in `ll /users/admin/output/ | awk '{print $9}'`&lt;BR /&gt;        do&lt;BR /&gt;                if [[ -s "$i" ]]&lt;BR /&gt;                then&lt;BR /&gt;                print $i&lt;BR /&gt;                mv /users/admin/output/$i /users/admin/output/keep/$i&lt;BR /&gt;                fi&lt;BR /&gt;        done&lt;BR /&gt;&lt;BR /&gt;rm /users/admin/output/late*&lt;BR /&gt;&lt;BR /&gt;Could anybody point me in the right direction??  Also, could you recommend a good book that I could use to learn from (one that contains good examples etc.)  Thank you in advance for any respone, they are very much appreciated.  &lt;BR /&gt;Best Regards, Barry.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 30 Nov 2000 10:37:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468982#M16274</guid>
      <dc:creator>Barry Deevey</dc:creator>
      <dc:date>2000-11-30T10:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468983#M16275</link>
      <description>Hello Barry&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;for i in `ll /users/admin/output/ | awk '{print $9}'` &lt;BR /&gt;do &lt;BR /&gt;      if [ -s "$i" ] &lt;BR /&gt;      then &lt;BR /&gt;            print $i &lt;BR /&gt;            mv /users/admin/output/$i /users/admin/output/keep/$i &lt;BR /&gt;      fi &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;rm /users/admin/output/late* &lt;BR /&gt;&lt;BR /&gt;Double brackets are not needed here, but be sure that there is a space between the opening bracket and the test flag, and before the closing bracket.&lt;BR /&gt;&lt;BR /&gt;ll may be replace by a 'ls -1', more effective, and avoiding an 'awk' pipe.&lt;BR /&gt;&lt;BR /&gt;As a starting point, you should buy the excellent book from O'Reilly: Unix in a nutshell.&lt;BR /&gt;&lt;BR /&gt;Hope this helps!&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Thu, 30 Nov 2000 10:52:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468983#M16275</guid>
      <dc:creator>Frederic Soriano</dc:creator>
      <dc:date>2000-11-30T10:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468984#M16276</link>
      <description>Hi Barry,&lt;BR /&gt;&lt;BR /&gt;# remove empty files first&lt;BR /&gt;find /users/admin/output -type f -size 0 -exec rm {} \;&lt;BR /&gt;# move the remaining files but not the keep directory&lt;BR /&gt;cd /users/admin/output&lt;BR /&gt;mv !(keep) keep&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Dan&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 30 Nov 2000 11:07:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468984#M16276</guid>
      <dc:creator>Dan Hetzel</dc:creator>
      <dc:date>2000-11-30T11:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468985#M16277</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;I forgot the book....&lt;BR /&gt;&lt;BR /&gt;Unix Power Tools&lt;BR /&gt;Jerry Peek, Tim O'Reilly and Mike Loukides&lt;BR /&gt;&lt;BR /&gt;O'Reilly and Associates&lt;BR /&gt;&lt;BR /&gt;ISBN 0-679-79073-x&lt;BR /&gt;&lt;BR /&gt;Dan</description>
      <pubDate>Thu, 30 Nov 2000 11:10:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468985#M16277</guid>
      <dc:creator>Dan Hetzel</dc:creator>
      <dc:date>2000-11-30T11:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468986#M16278</link>
      <description>For efficiency in scripting you could remove the ls altogether (if you don't want to use the find method)&lt;BR /&gt;&lt;BR /&gt;eg:&lt;BR /&gt;&lt;BR /&gt;for i in *&lt;BR /&gt;do&lt;BR /&gt;   if [[ -s ${i} ]]&lt;BR /&gt;   then&lt;BR /&gt;      mv ${i} ${KeepDir}&lt;BR /&gt;   else&lt;BR /&gt;      rm ${i}&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Thu, 30 Nov 2000 11:15:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468986#M16278</guid>
      <dc:creator>Open Systems</dc:creator>
      <dc:date>2000-11-30T11:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468987#M16279</link>
      <description>Just a quick note, the method described by Frederic did not seem to work, I'll continue to play around with it for my own education.&lt;BR /&gt;&lt;BR /&gt;Thank you all for your postings.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Barry.</description>
      <pubDate>Thu, 30 Nov 2000 13:25:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468987#M16279</guid>
      <dc:creator>Barry Deevey</dc:creator>
      <dc:date>2000-11-30T13:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468988#M16280</link>
      <description>Hello Barry,&lt;BR /&gt;&lt;BR /&gt;The problem with your script is that you are trying to test $i from your current directory.  You must put in the full path name in the if statement for it to work.&lt;BR /&gt;&lt;BR /&gt;Using Frederic's example (use single brackets), the if statement should read&lt;BR /&gt;&lt;BR /&gt;if [ -s "/users/admin/output/$i" ]&lt;BR /&gt;&lt;BR /&gt;You can also cd to /users/admin/output before doing the for loop.  This would allow you to remove the full path from the if statement.  Hope this helps.&lt;BR /&gt;&lt;BR /&gt;Josef</description>
      <pubDate>Thu, 30 Nov 2000 17:40:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2468988#M16280</guid>
      <dc:creator>Josef Nordtome</dc:creator>
      <dc:date>2000-11-30T17:40:41Z</dc:date>
    </item>
  </channel>
</rss>

