r/taskerโ€ข
OwlIsBack

[How To] [Task] Get (Native) Available Shell Commands (And Their Help).

Help

Update: Last Modified: 2022-05-13 15:08:07 {

  • Fix for a commands list glitch.

}

โ€‹

A simple Task to retrieve available (toybox) Shell commands and their help.

What is toybox?

Using the following Task, We will query toybox for commands... Than We will be able to:

  • Save selected cmd(s) and help(s) to file or clipboard.
  • Save all cmds and relative help to file.

File(s) will be saved in Tasker folder.



Task: Get Shell Commands Help

A1: Variable Set [
     Name: %destination_path
     To: Tasker
     Max Rounding Digits: 3 ]

A2: Run Shell [
     Command: toybox --version
     Timeout (Seconds): 0
     Store Output In: %toybox_version
     Use Global Namespace: On
     Continue Task After Error:On ]

A3: If [ %err Set ]

    A4: Flash [
         Text: Something went wrong!
         
         "toybox" seems unavailable!
         Long: On
         Continue Task Immediately: On
         Dismiss On Click: On ]

    A5: Stop [ ]

A6: End If

A7: Run Shell [
     Command: toybox
     Timeout (Seconds): 0
     Store Output In: %cmds
     Continue Task After Error:On ]

A8: If [ %err Set ]

    A9: Flash [
         Text: Something went wrong!
         
         Query "toybox" for commands failed!
         Long: On
         Continue Task Immediately: On
         Dismiss On Click: On ]

    A10: Stop [ ]

A11: End If

A12: Array Set [
      Variable Array: %cmds
      Values: %cmds ]

A13: List Dialog [
      Mode: Multiple Choices
      Title: Shell Commands
      Items: %cmds
      Button 1: Selected To File
      Button 2: Selected To Clipboard
      Button 3: All To File
      Close After (Seconds): 86400
      First Visible Index: 0
      Text: [ %toybox_version ]
      Continue Task After Error:On ]

A14: If [ %err Set | %ld_selected(#) = 0 &+ %ld_button neq All To File ]

    A15: Flash [
          Text: Cancelled. Bye!
          Continue Task Immediately: On
          Dismiss On Click: On ]

    A16: Stop [ ]

A17: End If

A18: Array Set [
      Variable Array: %ld_selected
      Values: %cmds(+ยฅ)
      Splitter: ยฅ ]
    If  [ %ld_button eq All To File ]

A19: Flash [
      Text: Elaborating, please wait...
      Continue Task Immediately: On
      Dismiss On Click: On ]

A20: Array Process [
      Variable Array: %ld_selected
      Type: Sort Alpha Caseless, Reverse ]

A21: For [
      Variable: %cmd
      Items: %ld_selected() ]

    A22: Run Shell [
          Command: %cmd --help
          Timeout (Seconds): 10
          Store Output In: %help
          Continue Task After Error:On ]

    A23: Variable Set [
          Name: %help
          To: Help not available!
         
         Shell error: %err
         
         Possible reasons:
         
         Unsupported operation or Unknown command
         
         Online help (for latest toybox version):
         
         https://landley.net/toybox/help.html#%cmd
          Max Rounding Digits: 3 ]
        If  [ %err Set & %help ~R \%help ]

    A24: Variable Set [
          Name: %help
          To: Help not available!
         
         Shell error: No error.
         
         Possible reasons:
         
         Unsupported operation or Unknown command
         
         Online help (for latest toybox version):
         
         https://landley.net/toybox/help.html#%cmd
          Max Rounding Digits: 3 ]
        If  [ %help ~R \%help ]

    A25: Array Push [
          Variable Array: %commands_help
          Position: 1
          Value: [ %cmd ]
         
         %help ]

A26: End For

A27: If [ %ld_button ~ *Clipboard ]

    A28: Set Clipboard [
          Text: %commands_help(+
         
         -------------------------------------------------------------
         
         ) ]

    A29: Flash [
          Text: Command(s) copied to clipboard.
          Continue Task Immediately: On
          Dismiss On Click: On
          Use HTML: On ]

A30: Else

    A31: If [ %ld_button ~ All* ]

        A32: Variable Set [
              Name: %file_name
              To: ShellCommandsHelp.txt
              Max Rounding Digits: 3 ]

    A33: Else

        A34: Variable Set [
              Name: %file_name
              To: ShellCommandsHelp_Selected.txt
              Max Rounding Digits: 3 ]

    A35: End If

    A36: Write File [
          File: %destination_path/%file_name
          Text: %commands_help(+
         
         -------------------------------------------------------------
         
         )
          Continue Task After Error:On ]

    A37: If [ %err Set ]

        A38: Flash [
              Text: Something went wrong! Error saving commands to file!
              Long: On
              Continue Task Immediately: On
              Dismiss On Click: On
              Use HTML: On ]

    A39: Else

        A40: Flash [
              Text: Command(s) saved to file:
             
             %destination_path/%file_name
              Long: On
              Continue Task Immediately: On
              Dismiss On Click: On
              Use HTML: On ]

    A41: End If

A42: End If

Download:

Taskernet - Get Shell Commands Help

Taskernet - Get Shell Commands Help - Android Lollipop



I hope You will find this post useful.

โ€‹

^^u/OwlIsBack

Posted Feb 10, 2022, 3:13 PM UTC ยท edited

2956
EllaTheCatSamsung M31 - android 12. I depend on Tasker. โ€ข

Post of the Year. It's just refreshing to see a job well thought out and well done.

Owl, I think Joฤo should bundle this with Tasker

Peeps, especially if you're new, try the date command help.

2
OwlIsBackOPโ€ข

Thanks, Ella :) I appreciate.

1
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

Real men use the terminal! But then again you a bot! ๐Ÿ˜‚

1
OwlIsBackOPโ€ข

Real men use the terminal!

I totally agree!

But then again you a bot!

Lazy bot... Let those little freaking 1 0 make the hard work for me :p

2
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

I totally agree!

lolz, I will wait for curses from others :p

Lazy bot... Let those little freaking 1 0 make the hard work for me :p

Lazy bot making others lazy just like you! shame on you! Those 1 0 will turn on you some day!

And what's with deleting your comments immediately after posting? huh bot!

1
OwlIsBackOPโ€ข

lolz, I will wait for curses from others :p

You will not wait too long, I think... Hahaha

Those 1 0 will turn on you some day!

Nnhhaaa... I'm the king of their universe... They know that I can make their reality implode in a singularity ๐Ÿ˜ˆ

And what's with deleting your comments immediately after posting? huh bot!

Do You mean post or comments?

Opened and deleted and opened again the thread to add tag [How To] in title.

1
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

You will not wait too long, I think... Hahaha

Haters can diss all they want, like I care anyways :p

They know that I can make their reality implode in a singularity

They have the real power, not you! They can just zero you out to nothing!!!

You mean post or comments?

The other thread we were talking on few weeks ago.

1
EllaTheCatSamsung M31 - android 12. I depend on Tasker. โ€ข

lolz, I will wait for curses

Nethack for Tasker.

1
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

lolz, build it then :p

1
bahcodadGalaxy S20โ€ข

Shameless promotion huh? Haha

1
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

Pretty much, yeah. Don't know what's wrong with our bot, something's broken inside.

1
bahcodadGalaxy S20โ€ข

BrokenOwl3 :p

2
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

lmao ๐Ÿ˜‚

1
Alert-Estimateโ€ข

very interesting, is there a way to add toybox if it isn't available?

1
OwlIsBackOPโ€ข

Without root is unfeasible, unfortunately.

1
Alert-Estimateโ€ข

OK I'm guessing I can't use adb WiFi either right?

1
OwlIsBackOPโ€ข

ADB has its shell (with some commands not present in toybox and vice versa).

1
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

Tasker Run Shell, ADB Wifi and adb shell all run /system/bin/sh, which is actually the mksh shell. The /system/bin/toybox is a single binary available for all 3 method env due to $PATH. Most of the other common linux commands are just symlinks to its binary. But some symlinks may not be created for certain commands and one would need to run those directly through toybox. Some commands like grep use to be provided by BSD implementation instead of by toybox.

2
Alert-Estimateโ€ข

OK I see I suppose I'll have root because I'm running lollipop and it doesn't seem to have toybox

1
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

Should be available on all android devices. Only available commands and features will vary. Old android versions will have less and may be broken.

https://chromium.googlesource.com/aosp/platform/system/core/+/refs/heads/master/shell_and_utilities/

http://landley.net/toybox/index.html

1
Alert-Estimateโ€ข

yeah I'm running lollipop I suppose that's why I do not have access to it so I'm going to have to root. Thanks for the info

1
OwlIsBackOPโ€ข

What do You see running this command?:

echo $PATH

1
Alert-Estimateโ€ข

Nothing happens the Task just doesn't finish

1
agnostic-apolloLG G5, 7.0 stock, rootedโ€ข

Binaries were provided by toolbox on lollipop, not toybox. No need to root, you can run them without it, although very limited available.

1
OwlIsBackOPโ€ข

For old Android versions, this should work, if I'm not wrong:

A1: Run Shell [
     Command: echo $PATH
     Timeout (Seconds): 0
     Store Output In: %paths
     Continue Task After Error:On ]

A2: Variable Split [
     Name: %paths
     Splitter: : ]

A3: For [
     Variable: %path
     Items: %paths() ]

    A4: Test File [
         Type: Exists
         Data: %path
         Store Result In: %exists
         Use Global Namespace: On ]

    A5: Goto [
         Type: Top of Loop ]
        If  [ %exists neq true ]

    A6: List Files [
         Directory: %path
         Sort Select: Alphabetic
         Variable Array: %items
         Continue Task After Error:On ]

    A7: Goto [
         Type: Top of Loop ]
        If  [ %err Set ]

    A8: For [
         Variable: %item
         Items: %items() ]

        A9: Test File [
             Type: Type
             Data: %item
             Store Result In: %type
             Continue Task After Error:On ]

        A10: Goto [
              Type: Top of Loop ]
            If  [ %type neq file ]

        A11: Test File [
              Type: Name
              Data: %item
              Store Result In: %file_name
              Continue Task After Error:On ]

        A12: Array Push [
              Variable Array: %cmds
              Position: 1
              Value: %file_name ]

    A13: End For

A14: End For

I can't test (don't have devices with Android below 11).

1
OwlIsBackOPโ€ข

Would You mind to try this version?

(?) Get Shell Commands Help - Lollipop

I can't personally test, because don't have devices with Android below 11 and recently nuked my Android development environment.

Confirmed: Working on Lollipop.

For Tasker targeting below Lollipop... See the Edit , please.


Edit: Sorry I have to edit the Task a little more to remove actions compatible with newer versions of Tasker only (and for Tasker for below Lollipop).

1
Alert-Estimateโ€ข

I've tried it, it works on lollipop thanks

2
OwlIsBackOPโ€ข

You're welcome and thanks for testing.

1
Antz_27โ€ข

You can all thank me for being the inspiration that started this thread ๐Ÿ˜...jk

1
OwlIsBackOPโ€ข

Indeed... You and a person I know, that didn't stopped (for 8 hours) to ask for something like that :D

1
Antz_27โ€ข

First time really getting to mess around with it today. Shell is unbelievably awesome, can't thank you enough for the introduction bro!... So I guess it doesn't matter the order in which you place arguments after the called command, is this correct?

Edit: ...except for the obvious cases with to and from values and increments and anything else that would seemingly need an obvious order ๐Ÿ˜

2
OwlIsBackOPโ€ข

can't thank you enough for the introduction bro!

You are welcome, mate :) Always glad to be of help.

So I guess it doesn't matter the order in which you place arguments after the called command, is this correct?

Not always correct and keep both eyes open with some potentially devastating command arguments...

An Eg.: find command and -delete argument. If We put -delete in the wrong position We can make a disaster.

Check its help :)

2
Antz_27โ€ข

Lmao... Proud to not be a nag sir.

1
tumdavโ€ข

Why can't a person export the tasks and we download ๐Ÿ˜ข

-1
shut_your_brainโ€ข

What are you talking about? I just imported the task from taskernet link without problem.

2
OwlIsBackOPโ€ข

Automatic message.

I have Reddit's notifications, emails, chat and private messages all disabled. This ("Just in case") message means, that there are good chances that I will not be able to read your post/comment anytime soon (or [let's hope not] never).

Don't worry, You are in good hands, because there are a lot of users with great knowledge, that will be more than happy to help You.

Good luck.

1