BLOCKSIZE for sh

Dear folks!

Please note: I don't want to change this, but understand, why this is set up this way.
I just had the same issue like here.

I checked out and learned: when using sh or cron or at, BLOCKSIZE is set, but for e.g. bash it is not. Therefore I added export BLOCKSIZE=512 to my script to have a more predictable behavior for my sizing (du).
(Sidenote: BLOCKSIZE is overriding du -B <any number>, wherever I tested.)

However, I am curious: why is this variable set for sh? Where else is this required besides du and so crucial it is set as a default?

Thanks for sharing your knowledge!

Regards
Dominik
 
[…] why is this variable set for sh?
BLOCKSIZE is set via /etc/login.conf(5). It gets set for all logins.​
Where else is this required besides du
According to environ(7) it is used by (FreeBSD’s implementations of) df(1) and ls(1), too. They do not require it though. getbsize(3) – which accesses the BLOCKSIZE environment variable – is also used by quot(8), pstat(8) and swapon(8).​
and so crucial it is set as a default?
I guess portability.​
The use of 512‐byte units is historical practice and maintains compatibility with ls and other utilities in this volume of POSIX.1‑2024. This does not mandate that the file system itself be based on 512‐byte blocks. The ‑k option was added as a compromise measure. It was agreed by the standard developers that 512 bytes was the best default unit because of its complete historical consistency on System V (versus the mixed 512/1024-byte usage on BSD systems), and that a ‑k option to switch to 1024‐byte units was a good compromise. Users who prefer the 1024‐byte quantity can easily alias du to du -k without breaking the many historical scripts relying on the 512-byte units.
Earlier versions of this standard did not have the ‑k option, which meant that the ‑s option could not be used portably as its block size was implementation‐defined, and the units used to specify the number of blocks occupied by files in a directory in an ls ‑l listing were fixed as 512‐byte units. The ‑k option has been added to provide a way for the ‑s option to be used portably, and for consistency it also changes the aforementioned units from 512-byte to 1024-byte.
The specific use of an environment variable to achieve portability, however:​
It was suggested that df and the various related utilities be modified to access a BLOCKSIZE environment variable to achieve consistency and user acceptance. Since this is not historical practice on any system, it is left as a possible area for system extensions and will be re‐evaluated in a future version if it is widely implemented.
[…] BLOCKSIZE is overriding du -B <any number>, wherever I tested. […]
Now this is documented in the manual page of du(1) though.​
‑B blocksize
Calculate block counts in blocksize byte blocks. This is different from […] setting BLOCKSIZE […]​
 
Back
Top