help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check if file size greater than a small number?


From: Alex fxmbsw7 Ratchev
Subject: Re: Check if file size greater than a small number?
Date: Thu, 10 Mar 2022 09:17:43 +0100

to use vars in functions -g em

On Thu, Mar 10, 2022, 04:48 Peng Yu <pengyu.ut@gmail.com> wrote:

> Hi Chet,
>
> > Perhaps convince Chet to make the stat loadable part of builtins, rather
> > than just an example builtin?
> >
> >   $ enable -f ./stat.so stat
> >   $ help stat
> >   stat: stat [-lL] [-A aname] file
> >       Load an associative array with file status information.
> >
> >       Take a filename and load the status information returned by a
> >       stat(2) call on that file into the associative array specified
> >       by the -A option.  The default array name is STAT.  If the -L
> >       option is supplied, stat does not resolve symbolic links and
> >       reports information about the link itself.  The -l option results
> >       in longer-form listings for some of the fields. The exit status is
> 0
> >       unless the stat fails or assigning the array is unsuccessful.
> >   $ stat -A motd /etc/motd
> >   $ declare -p motd
> >   declare -A motd=([type]="-" [gid]="0" [atime]="1646838713"
> > [mtime]="1515886594" [ctime]="1546663212" [device]="64768"
> > [blocks]="8" [perms]="0644" [inode]="8388721" [blksize]="4096"
> > [uid]="0" [size]="286" [nlink]="1" [link]="/etc/motd" [rdev]="0"
> > [name]="/etc/motd" )
>
> This seems to be buggy. When I put stat in a function, and declare a
> variable that is used as the -A option of stat. Nothing will be saved
> in the variable.
>
> function f {
>   declare -A fstat
>   stat -A fstat "$1"
>   declare -p fstat
> }
>
> $ f file.txt
> declare -- fstat
>
>
> If I use it as, the variable is still accessible outside the function.
>
> function f {
>   stat -A fstat "$1"
> }
>
> f file.txt
> declare -p fstat
>
> I think the variable scoping should be fixed.
>
> In the first case, `declare -A fstat` in a function, should not affect
> the result of stat. But that variable should not be available outside
> the function.
>
> --
> Regards,
> Peng
>
>


reply via email to

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