Running file without execute permissions


 
Thread Tools Search this Thread
# 1  
Lightbulb Running file without execute permissions

Please explain this strange behavior to me

Code:
bash-2.03$ ls -l abc
-rw-------   1   bashboy  users        319 Sep 21 18:02 abc
bash-2.03$ ./abc
bash: ./abc: Permission denied
bash-2.03$ . abc
Successfully run


I wanted to ask how the file executes without the execute permissions when we source the file.

Thank you
# 2  
Quote:
Originally Posted by rakeshou
I wanted to ask how the file executes without the execute permissions when we source the file.
Simple answer is it's not executing. It's being interpreted by the current shell.

Executing means "exec()" was called, which, in this case, is not the case.
# 3  
Isnt this the same case, when a script without execute bit set and passed to the base shell as an argument ?
Code:
zsh script.zsh

Here the file script.zsh is just an argument to the base binary zsh
# 4  
Sourcing a script

Unix programming Learning the Korn Shell, p 25, O'Reilly

There are three ways to run a script in Korn Shell (ksh):

1) $ . scriptname
Here you are running the script without creating a subshell, meaning that the new settings will be still in this shell after running the script. It's like copy/paste each line of the script in the shell.
This is also called sourcing because in csh and tcsh this is executed by running: $ sourse scriptname.
Also to run a script this way the script do not need execution permissions.

2) $ ./scritpname
Run the script in a subshell, after the script executes the shell will not have the new settings. Script need execution permissions.

3) $ scriptname
Run the script in a subshell, if . (current dir) is part of your cmd, searches in $PATH. The script needs execution permissions.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #935
Difficulty: Medium
A fixed 32-bit data format for system time means that timestamps rolls over approximately every 136 years, with the first such occurrence on 7 February 2036.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script without execute permissions will work for a user?

Please help me to understand the issue: Issue: There are shell scripts in a user home directory (/home/user_1) without execute permissions (rw-r--r--) to owner,group and world These shell scripts were able to execute/work previously but its not working now and it says permission denied or... (2 Replies)
Discussion started by: MSK_1990
2 Replies

2. Solaris

Script running even after execute permission removed.

Hi All, I'm new to solaris and this site but the advices in this site have helped me a lot. Today i am facing a new issue. We have a script for BMCDashboard and this script is not supposed to run evrytime the server is booted so we disabled the services and removed the execute... (7 Replies)
Discussion started by: Rockyc3400
7 Replies

3. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

4. Shell Programming and Scripting

How to execute cronjob running in a different machine?

Hi, I am developing 1 script in which I need to execute one cron job running in different server and my script is in different server. so can any one help me to execute the cronjob set in different server. Thanks in advance. (1 Reply)
Discussion started by: mridul10_crj
1 Replies

5. UNIX for Dummies Questions & Answers

Using find to search for any owner having execute permissions.

Hi I need help. I need to use find (or grep I don't care) to recursively search for files who have any kind of executable permissions (group and/or owner and/or other). I am looking for *.c and *.h This what I am using now: find . -name *.h -perm -111 -print but I don't want to retype that... (4 Replies)
Discussion started by: dissectcode
4 Replies

6. Solaris

Why user has permissions to execute 'init 0'?

Hi all. On one workstation run Solaris 10 a simple user can to execute 'init 0' command without input (su and root password). Example: % init 0 % OK I don't understand how user can execute 'init 0' command on this workstation? 1) I checked /usr/local/etc/sudoers all lines are... (6 Replies)
Discussion started by: wolfgang
6 Replies

7. UNIX for Dummies Questions & Answers

Default read/write/execute permissions

I am perplexed that my script execution is not always consistent in creating new files. Specifically, my group read/write/execute permissions. For instance, take a look at the following: -rw-rw---- 1 jg dp 18648 Aug 22 10:06 nx081508.txt -rw-rw---- 1 jg dp 22422 Aug 22 10:06... (1 Reply)
Discussion started by: joeyg
1 Replies

8. UNIX for Dummies Questions & Answers

help with permissions - execute but not delete

Hi, We have 2 users and one directory (dir). One user is admin user and other use r is operator user. who is responsible for just executing the scripts e.g. startWeblogic and stopWeblogic etc, we want to restrict this operator user in such a way that he can only execute these files and he should... (2 Replies)
Discussion started by: reldb
2 Replies

9. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

Featured Tech Videos