[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check if file size greater than a small number?
From: |
Peng Yu |
Subject: |
Re: Check if file size greater than a small number? |
Date: |
Wed, 9 Mar 2022 21:48:13 -0600 |
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
- Check if file size greater than a small number?, Peng Yu, 2022/03/09
- Re: Check if file size greater than a small number?, Dennis Williamson, 2022/03/09
- Re: Check if file size greater than a small number?, Jesse Hathaway, 2022/03/09
- Re: Check if file size greater than a small number?, Kerin Millar, 2022/03/09
- Re: Check if file size greater than a small number?,
Peng Yu <=
- Re: Check if file size greater than a small number?, Alex fxmbsw7 Ratchev, 2022/03/10
- Re: Check if file size greater than a small number?, Chet Ramey, 2022/03/10
- Re: Check if file size greater than a small number?, Jesse Hathaway, 2022/03/10
- Re: Check if file size greater than a small number?, Greg Wooledge, 2022/03/10
- Re: Check if file size greater than a small number?, Lawrence Velázquez, 2022/03/10
Re: Check if file size greater than a small number?, Alex fxmbsw7 Ratchev, 2022/03/09