[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] help
From: |
Dave Rutherford |
Subject: |
Re: [Help-bash] help |
Date: |
Sun, 6 Mar 2016 23:43:23 -0500 |
[moving this back to help-bash]
On Sun, Mar 6, 2016 at 10:44 PM, Val Krem <address@hidden> wrote:
> I created several files *.txt and when I execute the this command,
>
> autil +10 *txt
>
> It is listing the first file only!!!
That's because you need to escape the * or it will be
expanded too early. Try
autil +10 \*.txt
> function autil{
> /usr/bin/clear; autil
> }
This I don't understand. It is going to conflict with the other
function autil, below. Or it will run down the rabbit hole to
eventual stack overflow.
> autil() {
> if [ $# -lt 2 ]; then
> echo "Sorry, I need at least two parameters:"
> echo "The first is the time- how far should I go?"
> echo "The second is the name patternsuch as *txt"
> return 1;
> fi
> time=$1
You should quote "$1" there, because you should almost
always quote when something is user-supplied.
> shift #move all parameters over 1, dropping $1
> filetype="$1"
> shift #move all parameters over 1 again
> find -maxdepth 1 -type f -mtime ${time} -name "${filetype}"
> #find -maxdepth 1 -type f -mtime ${time} -name "${filetype}" "$@"
I see why you commented out the second "find"; it is because
when you specified "*.txt" as $2 it actually filled in "$@" with
syntactically invalid contents. If you properly escape the "*.txt",
you can restore the version which invokes "$@", which is really
a more useful version of your helper function here.