1841192 Members
4021 Online
110179 Solutions
New Discussion

. /etc/rc.config.d/cron

 
SOLVED
Go to solution
Guna_2
Regular Advisor

. /etc/rc.config.d/cron

Hi all

Is it possible to execute a file with . /scriptname which don't have execute permisson.

When i was looking the /sbin/init.d/cron script. I saw a line.


if [ -f /etc/rc.config.d/cron ] ; then
. /etc/rc.config.d/cron
else
echo "ERROR: /etc/rc.config.d/cron defaults file MISSING"
fi


what it mean . /etc/rc.confgi.d/cron Is it executing the script. And the file cron dont have execute permission also.

Can anyone please brief me.

Regards,
Guna
2 REPLIES 2
Steven Schweda
Honored Contributor
Solution

Re: . /etc/rc.config.d/cron

Please investigate the use of "?" in
questions.

In a Bourne (or Bourne-like) shell, ". file"
tells the current shell to read "file" and
to execute the commands in it. It does not
execute the script in the same way as a
simple "file" command, which would create a
new process running some shell which would be
reading "file".

". file" causes the current shell to read the
file, so only read permission is needed. For
example:

td176> cat ./z
echo fred

td176> ls -l z
-r--r--r-- 1 antinode 513 10 Feb 20 23:56 z

td176> ./z
sh: ./z: Execute permission denied.

td176> . ./z
fred


In a C shell, "source file" does the same
thing. See "man sh-posix".
A. Clay Stephenson
Acclaimed Contributor

Re: . /etc/rc.config.d/cron

To answer your question first question, "No" it is not possible to execute a file (at least directly) without the execute bit being set. However, you aren't asking the right question because the file to which you refer isn't being executed.

There is a profound difference between:
./etc/rc.config.d/cron
and
./etc/rc.config.d/cron

The first case, requires only read permission on the file while the second requires execute permission (and unless it is a true executable rather than a script, requires read permission as well).

The first case is using the shell's dot operator which has the effect of simply adding those lines to your existing script just as though they had been there all along. No child process is spawned and this means that if there is a return or exit statement in the file, the current process is terminated.

The second case actually spawns a separate process and anything such as variables being set occur in a child process and have no effect on the parent.
If it ain't broke, I can fix that.