[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] help
From: |
Val Krem |
Subject: |
Re: [Help-bash] help |
Date: |
Mon, 7 Mar 2016 07:18:39 -0600 |
Thank you Dave and John,
The function is listing the files !
Is there a way that I can assign the "+" and "\" inside the function? Instead
of writing as autitl +10 \•.txt,
I want write as
autil 10 •.txt
> On Mar 6, 2016, at 10:43 PM, Dave Rutherford <address@hidden> wrote:
>
> [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.