hi , i had a script , say script name , user and group had privilege to execute it . but my account does not belong to the group , so wen i ran the script ./scriptname , i got an error no privilege , but wen i use . ./scriptname it runs fine , how is this possible:eek:
hi... check if a script with the same name is present in the parent directory and that you have permissions on that script.
./scriptname
will try to execute the script in the current directory.
../scriptname
will try to execute the script in the parent directory.
so if you have permissions on the script in parent directory it will be executed.
Regards,
A!
Good catch!
Note : here parent directory referred by archimedes is the parent directory of the current directory. Don't mistake parent directory for home directory!
root@bt> pwd
/root/aen/tmp
root@bt> ls run
-rwxr-xr-x 1 root root 22 Jan 18 10:01 run*
root@bt> cd test
root@bt> pwd
/root/aen/tmp/test
root@bt> ls run
---------- 1 root root 22 Jan 18 10:56 run
root@bt> ../run
I got executed!
--ahamed
i did this
MITHUN> ls dsjob
dsjob
MITHUN> cd ..
MITHUN> ls dsjob
/bin/ls: dsjob: No such file or directory
i cannot find such a file in parent directory
hi,
so sorry.. i mistook
. ./scriptname
for
../scriptname
Failed to see the " " in between
can you please run this cmd and paste the output:
ls -ltr scriptname
maybe because your account doesnt belong to the group, you donot have executable permissions on it. so . ./scriptname works as it is an explicit cmd.
Regards,
A!
You probably have r(read) rights to the file, but not e(x)ecutable rights. Therefore you can read the script but not execute it. To keep scripts from being executed by users both r and x rights need to be removed. The dot is sourcing the file that contains the script. i.e. it is reading the file and executing the script in your current interactive shell, instead of a separate shell.
This should also work
/bin/sh ./scriptname
or whatever shell the script is supposed to be run with and it executes the script in a separate shell.
hi ,
I tried /bin/sh ./scriptname and it didnt work , this file sets environmental variable it seems ,
ls -ltr gives
-rwxr-xr-- 1 dsadm dstage 8841 2011-09-19 11:49 scriptname
when i try this . ./scriptname i can see new values are added to path . but sh scriptname or ./scriptname or /bin/sh ./scriptname does not set the new values to path
This is because only . ./scriptname
operates in your current working environment... This is called sourcing. The other commands open a subshell in which the commands are executed...
What do you mean it did not work? I presume you did not get an error this time, did you?