<?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: ksh script fails if runs from another dir, (for find:) in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-fails-if-runs-from-another-dir-for-find/m-p/4578669#M60372</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If you use wildcard characters in 'find' commands you need to quote the argument containing them so that the shell doesn't interpret them.  Rather, you want them passed to 'find' for it to interpret.&lt;BR /&gt;&lt;BR /&gt;In your case, most notably the '$MASK' variable contains a "*" character.  Depending on what's in or not it your starting directory this can cause different behavior.  To see what is really happending, change to your various directories and simply do:&lt;BR /&gt;&lt;BR /&gt;# echo ${MASK}&lt;BR /&gt;&lt;BR /&gt;For that matter, do :&lt;BR /&gt;&lt;BR /&gt;# echo *&lt;BR /&gt;&lt;BR /&gt;Instead of doing:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -name $MASK -mtime +$TERM -exec ls {} \;&lt;BR /&gt;&lt;BR /&gt;...do:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -name "$MASK" -mtime +$TERM -exec ls {} \;&lt;BR /&gt;&lt;BR /&gt;As an aside, it is also better (faster) to do:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -name "$MASK" -mtime +$TERM -exec ls {} +&lt;BR /&gt;&lt;BR /&gt;...which causes multiple arguments to be collected for each process spawned by '-exec'.  Thus, in this case, instead of running 'ls' for *each* object found, you run 'ls' for multiple arguments at a time.&lt;BR /&gt;&lt;BR /&gt;You might also want to limit your output to only files:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -type f -name "$MASK" -mtime +$TERM -exec ls {} +&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
    <pubDate>Thu, 04 Feb 2010 23:58:08 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2010-02-04T23:58:08Z</dc:date>
    <item>
      <title>ksh script fails if runs from another dir, (for find:)</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-fails-if-runs-from-another-dir-for-find/m-p/4578667#M60370</link>
      <description>Hello, all&lt;BR /&gt;&lt;BR /&gt;Hope you can easely point me what it wrong witmy setup, I created .ksh script with &lt;FIND&gt; command and I can't run it from one location and can run OK from another dir. what can be wrong ??&lt;BR /&gt;Tried absolutely everything, doen's matter what user, do it from command line with args.&lt;BR /&gt;&lt;BR /&gt;if fails get this:&lt;BR /&gt;find: paths must precede expression&lt;BR /&gt;Usage: find [-H] [-L] [-P] [path...] [expression]&lt;BR /&gt;&lt;BR /&gt;command itself is:&lt;BR /&gt;find $DIRR -name $MASK -mtime +$TERM -exec ls {} \;&lt;BR /&gt;I"ve played with qoutes around DIRR, no result either. I attached all info in .txt attached.&lt;BR /&gt;&lt;BR /&gt;Tx big to all&lt;BR /&gt;J&lt;BR /&gt;##################### my script:&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;DIRR=/$1&lt;BR /&gt;MASK=*.$2&lt;BR /&gt;TERM=$3&lt;BR /&gt;&lt;BR /&gt;echo " f11  gymscripts:  $1  2:$2  3:$3 "&lt;BR /&gt;echo " DIRR= $DIRR  term=$TERM for files with $MASK"&lt;BR /&gt;echo "  .... find coming "&lt;BR /&gt;&lt;BR /&gt;#ls -l $DIRR/$MASK&lt;BR /&gt;&lt;BR /&gt;find $DIRR -name $MASK -mtime +$TERM -exec ls {} \;&lt;BR /&gt;&lt;BR /&gt;echo "_______________ end"&lt;BR /&gt;######################################&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;find: paths must precede expression&lt;BR /&gt;Usage: find [-H] [-L] [-P] [path...] [expression]&lt;BR /&gt;_______________ end&lt;BR /&gt;&lt;BR /&gt;&lt;/FIND&gt;</description>
      <pubDate>Thu, 04 Feb 2010 22:43:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-fails-if-runs-from-another-dir-for-find/m-p/4578667#M60370</guid>
      <dc:creator>JianW</dc:creator>
      <dc:date>2010-02-04T22:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script fails if runs from another dir, (for find:)</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-fails-if-runs-from-another-dir-for-find/m-p/4578668#M60371</link>
      <description>Shalom,&lt;BR /&gt;&lt;BR /&gt;If your script sets the PATH environment to include where find command actually is, this kind of inconsistency can be avoided.&lt;BR /&gt;&lt;BR /&gt;There also appears to be a possible problem with one of the variables on the find line, $DIRR $MASK or $TERM being wrong.&lt;BR /&gt;&lt;BR /&gt;Also remember that / is interpreted differently by the shell and may need to be escaped.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Thu, 04 Feb 2010 23:11:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-fails-if-runs-from-another-dir-for-find/m-p/4578668#M60371</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2010-02-04T23:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script fails if runs from another dir, (for find:)</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-fails-if-runs-from-another-dir-for-find/m-p/4578669#M60372</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If you use wildcard characters in 'find' commands you need to quote the argument containing them so that the shell doesn't interpret them.  Rather, you want them passed to 'find' for it to interpret.&lt;BR /&gt;&lt;BR /&gt;In your case, most notably the '$MASK' variable contains a "*" character.  Depending on what's in or not it your starting directory this can cause different behavior.  To see what is really happending, change to your various directories and simply do:&lt;BR /&gt;&lt;BR /&gt;# echo ${MASK}&lt;BR /&gt;&lt;BR /&gt;For that matter, do :&lt;BR /&gt;&lt;BR /&gt;# echo *&lt;BR /&gt;&lt;BR /&gt;Instead of doing:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -name $MASK -mtime +$TERM -exec ls {} \;&lt;BR /&gt;&lt;BR /&gt;...do:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -name "$MASK" -mtime +$TERM -exec ls {} \;&lt;BR /&gt;&lt;BR /&gt;As an aside, it is also better (faster) to do:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -name "$MASK" -mtime +$TERM -exec ls {} +&lt;BR /&gt;&lt;BR /&gt;...which causes multiple arguments to be collected for each process spawned by '-exec'.  Thus, in this case, instead of running 'ls' for *each* object found, you run 'ls' for multiple arguments at a time.&lt;BR /&gt;&lt;BR /&gt;You might also want to limit your output to only files:&lt;BR /&gt;&lt;BR /&gt;# find $DIRR -type f -name "$MASK" -mtime +$TERM -exec ls {} +&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Feb 2010 23:58:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-fails-if-runs-from-another-dir-for-find/m-p/4578669#M60372</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-02-04T23:58:08Z</dc:date>
    </item>
  </channel>
</rss>

