Using internal command sh to run linux command, output is scrambled

Support for Android version of Total Commander

Moderators: petermad, Stefan2, Hacker

Post Reply
Tcny
Junior Member
Junior Member
Posts: 10
Joined: 2024-08-29, 00:45 UTC

Using internal command sh to run linux command, output is scrambled

Post by *Tcny »

I am using the latest version of Total Commander for Android on a Samsung S22 Ultra with the latest Android and OneUI code, as well as the latest version of Toybox. I created a button to run the sh command, setting the parameters field to
"* find . -type f -exec ls -l --full-time {} \;"

When run, I get a list of files shown like this
permissions 1 u0a287 media_rw 34 2025-04-11 20:31:19.193887122-0400 ./file1.txt


I then tried to changed the parameters to be
"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%7s %s %s\n", $5, %7 %8 }'

I was expecting to get something like
" 34 20:31:19.193887122-0400 ./file1.txt"

but instead I get just
" 34"

Is this just a Toybox bug, or am I doing something wrong ?

By the way, the "*" causes the results to be displayed in a pop up dialog box, when you can close it after viewing.

Thanks for your help.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53162
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Using internal command sh to run linux command, output is scrambled

Post by *ghisler(Author) »

You are missing a comma between %7 and %8, and shouldn't they be $7 and $8?
Author of Total Commander
https://www.ghisler.com
Tcny
Junior Member
Junior Member
Posts: 10
Joined: 2024-08-29, 00:45 UTC

Re: Using internal command sh to run linux command, output is scrambled

Post by *Tcny »

I made a typing mistake. I am writing these posts on a laptop, yet doing the work on an Android phone. That command I used was actually

"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%7s %s %s\n", $5, $7, $8 }'

I can even simplify that and try

"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%s\n", $7 }' OR
"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%s\n", $8 }'

Those do not yield expected results, the $7 and $8 fields are not shown.

After just playing around I see that something like this

"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%07s %16s %16s\n", $5, $6, $9 }'

results in

"0000034 2026-04-11 ./f1.txt"

If I do not include the length "flag", like the '16' above, then the value is NOT shown. For some reason the filename is $9 not $8. Using '%07s" leads to the file size of "0000034", but using '%7s' does NOT lead to 5 spaces, and 34 (...or the font is NOT fixed width ??).

To be clearer,

"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%16s\n", $9 }'

will show the filename,

"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%s\n", $9 }'

will NOT.

As a software developer, I understand software is rarely perfect, so will figure out a work around to achieve my goals.
Tcny
Junior Member
Junior Member
Posts: 10
Joined: 2024-08-29, 00:45 UTC

Re: Using internal command sh to run linux command, output is scrambled

Post by *Tcny »

I did some more playing around, using sh and the cksum command ...

My sh parameters were: "* for file in %S; do cksum $file;done"

This worked with two files selected. I then tried: "* for file in %S; do cksum $file | awk '{ printf "%12s %8s %1s" }';done"

The output WAS NOT spaced properly ... the first 2 fields did NOT appear to take up the specified width. I then tried:
"* for file in %S; do cksum $file | awk '{ printf "%012s %08s %1s" }';done"

and now everything is in perfect columns. This led me to believe the problem is not with my command syntax, but rather what ever is displaying the results in the temporary 'dialog' box. I then tried this: "* for file in %S; do cksum $file | awk '{ printf "%12s %8s %1s" >> "./cks.txt" }';done"

That resulted in a text file "cks.txt" in the current directory with output in perfect columns. In further experimenting I found that using the sh command to output text does so with letters and numbers being displayed in a "fixed width" font. Spaces and symbols like !@#$%^&*( are NOT shown in fixed width font.
JOUBE
Power Member
Power Member
Posts: 1930
Joined: 2004-07-08, 08:58 UTC

Re: Using internal command sh to run linux command, output is scrambled

Post by *JOUBE »

Tcny wrote: 2026-04-12, 14:36 UTC For some reason the filename is $9 not $8.

....

"* find . -type f -exec ls -l --full-time {} + | awk '{ printf "%16s\n", $9 }'
--full-time (already) like -l --time-style=full-iso

And I would always use instead for such outputs:

-l --time-style=+"%F %T"
Tcny
Junior Member
Junior Member
Posts: 10
Joined: 2024-08-29, 00:45 UTC

Re: Using internal command sh to run linux command, output is scrambled

Post by *Tcny »

I found that a string such as "20:31:19.193887122-0400" was be treated as two strings, "20:31:19.193887122" and "-0400".
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53162
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Using internal command sh to run linux command, output is scrambled

Post by *ghisler(Author) »

That's odd, the default field separator should be a space. Maybe you can set it explicitly via -F switch, e.g.
awk -F' ' '{ printf "%16s\n", $8 }'
Author of Total Commander
https://www.ghisler.com
Tcny
Junior Member
Junior Member
Posts: 10
Joined: 2024-08-29, 00:45 UTC

Re: Using internal command sh to run linux command, output is scrambled

Post by *Tcny »

I have my project working. Thanks for the help for those responding.

Just curious, does anyone know if there is a character limit to the size of the "parameters" for the internal sh command ?
JOUBE
Power Member
Power Member
Posts: 1930
Joined: 2004-07-08, 08:58 UTC

Re: Using internal command sh to run linux command, output is scrambled

Post by *JOUBE »

xargs --show-limits
getconf ARG_MAX
Post Reply