Saturday, May 4, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 885  / 2 Years ago, mon, august 1, 2022, 3:21:39
compgen -c | sort -b | uniq | less

Shows also functions and keywords (luckily no aliases), I instead want all that are not keywords, functions or aliases. In few words only the commands.


If command name match with function name, keyword name or alias name; the command name must not be omitted.


More From » command-line

 Answers
2

For compgen (and I think for Linux in general), a command is everything that you can run including alias' and functions, etc.


If you want to get only executable files/scripts in any of your $PATH directories, there is no good way using compgen.


You could use comm to show all commands excluding aliases, keywords and functions:


comm -23 
<(compgen -c | sort -u)
<(compgen -akA function | sort -u)

However, this will also remove commands that are both alias/function and command (e.g. ls or grep have an alias per default in Ubuntu, as well as anything you added yourself).


So, I think you're better off getting all executables from $PATH with your own script (and if you wish you can add builtins using compgen -b):


path_filenames(){
printf '%s' "$PATH"
| xargs -d: -I{} -- find -L {} -maxdepth 1 -executable -type f -printf '%P
' 2>/dev/null
}

sort -u <(path_filenames) <(compgen -b)

[#1867] Wednesday, August 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cretanol

Total Points: 320
Total Questions: 99
Total Answers: 115

Location: Australia
Member since Sat, May 27, 2023
1 Year ago
cretanol questions
Fri, Dec 2, 22, 13:30, 1 Year ago
Thu, Dec 8, 22, 03:00, 1 Year ago
Fri, Sep 24, 21, 16:28, 3 Years ago
Sun, Apr 24, 22, 06:37, 2 Years ago
;