[Solved] Alias don't output with TAB and LF ?

SpongeB0B

Member
Joined
Feb 11, 2022
Messages
30
Reaction score
7
Credits
270
Hi everyone,

when I enter this in the terminal

Bash:
stat --printf="%a\t%A\t%U\t%G\t%s\t%.19y\t%F\t%n\n" * | numfmt --to=iec-i --field=5 --delimiter='    ' --suffix=B

I got what is expected:
Bash:
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-28 07:09:20    directory    Desktop
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-07 06:41:52    directory    Documents
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-07 06:41:52    directory    Downloads
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-07 06:41:52    directory    Music
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-07 06:41:52    directory    Pictures
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-07 06:41:52    directory    Public
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-07 06:41:52    directory    Templates
755    drwxr-xr-x    virtua    virtua    4.0KiB    2022-02-07 06:41:52    directory    Videos

But when I turn it into an alias in /root/.bashrc
Bash:
alias statcs="stat --printf="%a\t%A\t%U\t%G\t%s\t%.19y\t%F\t%n\n" * | numfmt --to=iec-i --field=5 --delimiter='    ' --suffix=B"

I got one giant string without TAB or LF when I call the alias statcs
Bash:
755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-28 07:09:20tdirectorytDesktopn755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-07 06:41:52tdirectorytDocumentsn755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-07 06:41:52tdirectorytDownloadsn755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-07 06:41:52tdirectorytMusicn755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-07 06:41:52tdirectorytPicturesn755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-07 06:41:52tdirectorytPublicn755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-07 06:41:52tdirectorytTemplatesn755tdrwxr-xr-xtvirtuatvirtuat4096t2022-02-07 06:41:52tdirectorytVideosn

any ideas ?

Thanks
 


To get your stat command to work, I had to reduce the delimiter to a single character, or it complained. I changed it to a space.
Then the stat command worked in the terminal as user and as root.
In the terminal:
Code:
[root@owl ~/lemon]# stat --printf="%a\t%A\t%U\t%G\t%s\t%.19y\t%F\t%n\n" * | numfmt --to=iec-i --field=5 --delimiter=' ' --suffix=B
755     drwxr-xr-x      root    root    4096    2022-03-11 20:54:34     directory       a0
755     drwxr-xr-x      root    root    4096    2022-03-10 11:02:43     directory       a1
755     drwxr-xr-x      root    root    4096    2022-03-10 11:02:43     directory       a2
755     drwxr-xr-x      root    root    4096    2022-03-10 11:02:43     directory       a3
In .bashrc as the alias statcs, it didn't work:
Code:
[root@owl ~/lemon]# statcs
755tdrwxr-xr-xtroottroott4096t2022-03-11 20:54:34tdirectoryta0n755tdrwxr-xr-xtroottroott4096t2022-03-101:02:43tdirectoryta1n755tdrwxr-xr-xtroottroott4096t2022-03-10 11:02:43tdirectoryta2n755tdrwxr-xr-xtroottroott4096t2022-03-10
numfmt: invalid suffix in input: ‘11:02:43tdirectoryta3n’
However, there is an error message in the last line from my bash output, but your output lacks it.

Nevertheless, when I put your command in a script:
Code:
[root@owl ~/lemon]# cat statcs1
#!/bin/bash
#statcs1 - directory formatter
stat --printf="%a\t%A\t%U\t%G\t%s\t%.19y\t%F\t%n\n" * | numfmt --to=iec-i --field=5 --delimiter=' ' --suffix=B
The output is the intended one, with the extra file recording itself:
Code:
[root@owl ~/lemon]# ./statcs1
755     drwxr-xr-x      root    root    4096    2022-03-11 20:54:34     directory       a0
755     drwxr-xr-x      root    root    4096    2022-03-10 11:02:43     directory       a1
755     drwxr-xr-x      root    root    4096    2022-03-10 11:02:43     directory       a2
755     drwxr-xr-x      root    root    4096    2022-03-10 11:02:43     directory       a3
775     -rwxrwxr-x      root    root    124     2022-03-11 21:21:56     regular file    statcs1

So, it looks like if you want it to work in root, you could create a script rather than an alias.
 
Last edited by a moderator:
But when I turn it into an alias in /root/.bashrc
Bash:
alias statcs="stat --printf="%a\t%A\t%U\t%G\t%s\t%.19y\t%F\t%n\n" * | numfmt --to=iec-i --field=5 --delimiter='    ' --suffix=B"
The problem with your alias is that your quotes are mis-matched.
Your double quote after printf= is NOT acting as an opening quote for your printf format string. It's actually acting as a closing quote for the opening quote after statcs=.
So everything inside your printf format string and afterwards is technically outside of the alias definition.

I'd recommend using single quotes to enclose the entire alias and then use double quotes for specifying your printf format string and your delimiter.

So this will work as an alias:
Bash:
alias statcs='stat --printf="%a\t%A\t%U\t%G\t%s\t%.19y\t%F\t%n\n" * | numfmt --to=iec-i --field=5 --delimiter=" " --suffix=B'

As mentioned by @NorthWest - I also got errors when using a multi-character delimiter, so I've just used a single space as the delimiter.
 

Staff online

Members online


Top