0

I am trying to run a shell script that contains the command

$locate /etc/*.conf

to find all files in /etc/ that end in .conf, but whenever I run the script the command line says /etc/chrony.conf: Permission denied. Whenever I run the command on its own in the command line it executes fine but from the script it fails. I have updated the script permissions with chmod, tried running the script with sudo privileges, giving sudo privileges inside the script itself, and even logging in as root but it is still saying permission denied.

Any help is appreciated, thanks!

1 Answer 1

0

Remove the dollar sign.

When you write $locate the shell looks for the the variable named "locate" not the executable.

Because you don't have a variable named "locate" you are effectively calling:

/etc/*.conf

The glob expands to all the files that match it and the shell wants to execute those files. The first file name in your case is /etc/chrony.conf and because that file is not an executable, it throws the error.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .