Re: passing a number as parameter1 to the script

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 03/11/05


Date: 11 Mar 2005 16:58:14 GMT

On Fri, 11 Mar 2005 at 16:47 GMT, prabhat143@gmail.com wrote:
> Hi,
>
> I have been using the following command recently.
>
> find "$@" -type f -atime +$10
>
> to get the list of all files that are 10 days old. I am trying to write
> a bash shell script(call it listFiles.sh) where user can specify number
> of days as the first parameter to the script and output will be list of
> all files in the current directory and its subdir which are older than
> the user specified date. To be precise, user will call
>
> bash> listFiles.sh 15 //will list files which 15 or more days older
>
> Here is the script I wrote and it gives me an error that I dont know
> how to fix.
>
> ---start of script
> numDays=$1
> echo "Number of days specified " $numDays \;
> find "$@" -type f -atime +$numDays
> ---end of script
>
> The output when given 15 as parameter is:
> Number of days specified 15 ;
> find: 15: No such file or directory
>
> What do I need to do to pass 15 as parameter to -atime flag?

   Remove the first positional parameter; you are passing it to find
   in "$@". And you probably want -mtime not -atime.

numDays=$1
echo "Number of days specified " $numDays \;
shift
find "$@" -type f -mtime +$numDays

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2005, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: IPC::Open2::open2() -- How to pass strings stdin, stdout?
    ... Hardly even worth a sub ... Execute a given external program (command). ... first parameter, and the input data as the second parameter. ... my $stdin = shift; ...
    (comp.lang.perl.misc)
  • getopt or optparse options/arguments wrapping?
    ... This is something like the shell script like this: ... -a) do-something; shift ... # execute the command with $optwrap as subprocess ... scripts command line will be used by executing the sub command. ...
    (comp.lang.python)
  • Re: suppress command line option with hyphen
    ... The "-u" command line parameter is useless and I want to suppress it ... inside the script. ... -u) shift ...
    (comp.unix.shell)
  • Re: match machine name to user name
    ... WScript.Echo to write out status from your script that is called from ... the batch file, the message will be displayed inside the batch file ... first parameter that was sent in to the batch file on the command ... on the command line etc. ...
    (microsoft.public.scripting.vbscript)
  • Re: help w/sed
    ... I am trying to write a script that does this. ... > echo $a ... > shift 2 ... temporary file properly (and remember to close the s command): ...
    (comp.unix.shell)