Not sure I can ask It here. I gave an interview yesterday and Interviewer asked me question " Is 'ls' a command. If yes, Explain how ? " and I was totally puzzled by it. I just explained what is 'ls' used for, and now I am confused about 'ls' being a command. Someone please enlighten me.
I executed "type" and "file" commands to know what exactly it is and came to conclusion that "It is an executable" . Would saying "ls is an executable" as an answer be right ?
There's a strong difference between a builtin and a keyword, in the way Bash parses your code. Before we talk about the difference, let's list all keywords and builtins:
Builtins:
$ compgen -b
. : [ alias bg bind break
builtin caller cd c...
@C0deDaedalus Their selection may have been based on something other than the answer to that particular question.
ls is a command. Sometimes it's referred to as a utility.
Built-in commands are also commands.
while and if on the other hand, are keywords.
A shell may choose to provide any command as a built in command, even ls. So the distinction between "a command" and "a built in command" does not really matter.
time may be a keyword in one shell, but it's not standard. In fact, on my machine, I have time as a keyword, but I also have /usr/bin/time which does a similar thing.
Had the question been "is time a command?", then "yes" would have been a correct answer.
"No" would also have been a correct answer. It depends on how you use the keyword or the command.
Without context, the answer "No, 'ls' are two characters" would have been correct too :-)
@FaheemMitha The point of the bad writing in most spam messages is to be badly written enough that only people dumb enough to be easily defrauded will believe them.