bug-bash
[Top][All Lists]
Advanced

[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 03:44:15 +0000 (UTC)

Hi John and all,

I created several files *.txt and when I execute the this command, 


autil +10  *txt


It is listing the first file only!!!


function autil{
   /usr/bin/clear; autil
}


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
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}" "$@"


Val




On Sunday, March 6, 2016 8:05 PM, John McKown <john.archie.mckown@gmail.com> 
wrote:



Please reply to the list and not just me. There are a lot of helpful people out 
there. Perhaps a "reply all"?


On Sun, Mar 6, 2016 at 5:26 PM, Val Krem <valkrem@yahoo.com> wrote:

Hi John,
>Thank you very much!
>I chose to put it as a function in my .bashrc.
> what happened is that
>if I dot give the the two arguments then
>
>ie.,
>
>1. if I type autil  : it automatically closed the terminal
>2. if I give the two arguments
>
>  ie.,  autil 10 *.txt I go this message
>
>Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] 
>[path...] [expression]
>
>
>******************************
>
>function 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 or *csv"
>exit 1
>

​You didn't notice in the function version that I changed this from "exit 1" to 
"return 1". BASH functions need the return command.
​ 
fi
>time=$1
>shift #move all parameters over 1, dropping $1
>filetype="$2"
>

​Oh, my, I made another mistake here. This line should be:

filetime="$1"​

 
shift #move all parameters over 1 again
>
>find -maxdepth 1 -type f -mtime ${time} -name "${filetype}" "$@"
>}
>
>**************************
>
>
>
>Is it possible to fix it??
>

​function 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 or *csv"
return 1
fi
time=$1
shift #move all parameters over 1, dropping $1
filetype="$1" #error in original, it used "$2", BAD ME
shift #move all parameters over 1 again

find -maxdepth 1 -type f -mtime ${time} -name "${filetype}" "$@"
}
​

 
1. why it is closing the terminal?
>

​ The "exit" will, as you noticed, exit the BASH shell itself.​ Look closely at 
the following transcript:

===
$ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
joarmc   15690  3701  0 19:49 pts/2    00:00:00 /bin/bash
joarmc   16290 15690  0 19:50 pts/2    00:00:00 ps -f

$echo $$
15690

$cat t1.sh 
#!/bin/bash
echo $$
ps -f

$./t1.sh 
16617
UID        PID  PPID  C STIME TTY          TIME CMD
joarmc   15690  3701  0 19:49 pts/2    00:00:00 /bin/bash
joarmc   16617 15690  0 19:52 pts/2    00:00:00 /bin/bash ./t1.sh
joarmc   16618 16617  0 19:52 pts/2    00:00:00 ps -f

$function t2() {
> echo $$
> ps -f
> }

$t2
15690
UID        PID  PPID  C STIME TTY          TIME CMD
joarmc   15690  3701  0 19:49 pts/2    00:00:00 /bin/bash
joarmc   16711 15690  0 19:52 pts/2    00:00:00 ps -f

$
===
​
​Notice the PID in the function example is the same as the /bin/bash. Also 
notice that when I run t1.sh, you see it in the list as "/bin/bash ./t1.sh"​. 
But notice when I run t2, the PID is the same as the top /bin/bash and there is 
_no_ sign of "t2" itself. That's because the current BASH program is running 
the function "in line". So an "exit" in the function is like typing "exit" at 
the prompt and "the terminal goes away"


>--
>A fail-safe circuit will destroy others. -- Klipstein
>
>Maranatha! <><
>
>John McKown
>



-- 

A fail-safe circuit will destroy others. -- Klipstein


Maranatha! <><
John McKown


reply via email to

[Prev in Thread] Current Thread [Next in Thread]