1
% print ok
ok
% sudo print ok
sudo: print: command not found

It seems the print are not properly loaded. So what happened and how can I fix it?

Anon
  • 395

1 Answers1

-1

I found the reason should be that sudo command invokes the sh as a default shell to root user, and there is no command called 'print' in sh.

Anon
  • 395
  • 2
    No, sudo doesn't invoke sh, it executes the command directly (unless you pass the -s option, in which case it invokes the shell specified in $SHELL after having attempts to quotes the arguments). print is a builtin command in ksh or zsh, some systems don't have a standalone print command, and on those that have one, it's generally got nothing to do with zsh's print builtin. – Stéphane Chazelas Jul 30 '20 at 16:23
  • @StéphaneChazelas But if the shell didn't get changed, why the print can not be found in the same environment of the case without a sudo? The sudo command explicitly refuses to run it? – Anon Jul 30 '20 at 16:38
  • 3
    zsh executes the sudo command, and then sudo tries to execute the print command. There is no such command on your system, only a builtin command in the zsh shell. You'd need sudo zsh -c 'print ok' for sudo to execute a zsh command (which contrary to print does exist, probably in /bin or somewhere else, see the output of type print zsh), to interpret that print ok inline script. And that zsh would invoke its own print builtin command with ok as argument. – Stéphane Chazelas Jul 30 '20 at 16:42