Count Number of Commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Steel546
    New Member
    • Mar 2009
    • 25

    #1

    Count Number of Commands

    So I've been trying to print all of the commands to one file on new lines, and then count them. The problem I'm getting is that I can't get all the commands into a file. I've tried assigning <TAB> to a value to do tab twice and list all commands, but to no avail.

    Does anyone have any suggestions?
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    You can parse the $PATH env variable.
    It will basically contains the paths where all executable resides. Now you can 'ls -l' those directories and filter out entries where 'x' flag is not set. (i.e. file has no executable permission). Those files have 'x' set choose that and redirect it to new file. Make sense?

    Comment

    • Steel546
      New Member
      • Mar 2009
      • 25

      #3
      I kinda had that going for a minute after I posted this and just searched through the root directory in /bin and /sbin, but yours seems more thorough, lol.

      One of my friends pointed out that the question actually says "Write a shell script that prints the NUMBER of command line arguments." That threw me off because now we don't know if he wants COMMANDS or COMMAND [argument]. I appreciate the help though!

      Comment

      Working...