Skip to content

Source command not found Amazon Linux 2023

0

Trying to reload *.rc file via sudo . /path/*.rc or sudo source /path/*.rc. Console throws error "command not found".

asked 3 years ago1.7K views

3 Answers
0

I think the following methods can solve the problem.
The "source" command will cause an error if it is executed with "sudo".
So I think changing to the root user and then running it will solve the problem.
https://askubuntu.com/a/20955

EXPERT

answered 3 years ago

  • [root@ip-xxx-xxx-xxx-xxx ec2-user]# source /etc/mail.rc bash: ignore: command not found bash: ignore: command not found bash: fwdretain: command not found

  • The "ignore" and "fwdretain" commands are said to be missing. Do you have the path settings listed in the "/etc/mail.rc" file? Also, are the commands "ignore" and "fwdretain" installed on Amazon Linux 2023? You can check the path with the following command.

    which ignore
    which fwdretain
    

    After checking, make sure that the path is in "/etc/mail.rc".

0

source and . are shell built-in commands. They execute the command you want within the context of the current process. So trying to run them using sudo which will create a new process doesn't make much sense.

Also, you can't execute multiple commands with a wildcard. With *.rc the shell will expand that to first.rc second.rc third.rc which means "execute first.rc with second.rc and third.rc as parameters".

What I think you're trying to do is run a bunch of commands in a directory as the root user. There are probably a thousand ways to do that but you might try:

for command in /patch/*.rc
 do
  sudo ${command}
 done
EXPERT

answered 3 years ago

  • .... create a new process doesn't make much sense.

    For instance, how to reload /etc/mail.rc if not using sudo?

  • The commands in my answer will do that for you.

0

as a sum up

Instead of running "sudo source /path/*.rc", you can use one of the following alternatives

sudo bash -c "source /path/*.rc"

source <(sudo cat /path/*.rc)

sudo su
source /path/*.rc
EXPERT

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.