I dont understand what does this programme does :
if command -v apt-get > /dev/null; then
dpkg-query -W -f='...'
i dont understand how the command : "command" works
I dont understand what does this programme does :
if command -v apt-get > /dev/null; then
dpkg-query -W -f='...'
i dont understand how the command : "command" works
There are different ways to do things in the shell.
The default is to execute shell builtins.
Next commands (binaries, scripts, etc; basically something external to the shell) are looked up in the directories listed in the PATH variable.
This is followed by aliases. These are reusable abbreviations to commands, you can think of them as a way to save typing. They are usually defined in the shell's rc files. For example I have this defined in my ~/.bashrc: alias lt='ls --color=tty -lhtr'; it lets me type only lt to get a reverse sorted list of files (newest at the bottom).
More complex commands can be grouped into shell functions.
The command command is a shell builtin that allows you to bypass any functions that might also match a binary in your PATH, or any aliases. Say I use rsync frequently between specific hosts, so I wrote a function called rsync that includes the destination with all the options, allowing me to type less. However if I want to run rsync with a different destination, I could use command rsync <other rsync options> to bypass the function definition. Note that aliases are not bypassed; this is relevant if you are using command interactively. You can find the documentation in the builtin page linked above, or by typing help command
See man bash or help command in bash for help:
Runs COMMAND with ARGS suppressing shell function lookup, ...
The if checks whether there is a command apt-get; if there is a function apt-get, it's ignored.