Executing file without excute permission.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Executing file without excute permission.
# 1  
Old 05-08-2008
Executing file without excute permission.

Hi,

I have a file which don't have execute permission, but still it can be executed by "sh" like as below.
------------------------------------------------------------------
-rw-r----- 1 root other 30 May 8 15:43 test.sh
(svpkg1-nd:root) - ./test.sh
./test.sh: cannot execute
(svpkg1-nd:root) - sh test.sh
I am here
(svpkg1-nd:root) -
-----------------------------------------------------------
Please tell me the difference between these two ways of executions.
In this way other if other users have only read permission still they can execute the file.

Thanks in advance,
Ashish
# 2  
Old 05-08-2008
Hi,
here are some ideas but i might be totally wrong:
- in the first case, since test.sh has no exec attribute, you get "cannot execute" error
- in the second case, you are telling the binary-executable 'sh' to run commands you pass as parameters (test.sh) ...
You need to strip out read attribute if you dont want the second case happening
# 3  
Old 05-08-2008
Just to complement andryk answer, if you want to execute it as ./test.sh, you should put the executable flag in it, and you shell script should begin with the line:
Code:
#!/bin/sh

And here's to put the executable flag
Code:
chmod u+x test.sh

# 4  
Old 05-08-2008
Quote:
Originally Posted by Zarnick
Just to complement andryk answer, if you want to execute it as ./test.sh, you should put the executable flag in it, and you shell script should begin with the line:
Code:
#!/bin/sh

And here's to put the executable flag
Code:
chmod u+x test.sh

This first line is there in file. I am asking for difference of executing first way and second way
# 5  
Old 05-08-2008
./filexy.sh requires the script to open the shell - what cannot be done without the x permission

doing sh filexy.sh means you open the shell and the script is passive executed in this shell ...

As long as you are allowed to use the shell you can execute the scripts this way

Rgds
zx
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing bash file with sudo for the second time, leads to permission denied, for some commands

I have a script that checks if the script has been ran with sudo. If the script is not ran as sudo, the current script is being executed with exec sudo bash. You are asked for a password, you type in the password, success. Everything is perfect - the commands inside the script are ran as sudo.... (1 Reply)
Discussion started by: boqsc
1 Replies

2. SuSE

cant excute /etc/init/rc*

hi Guys, i'm new to linux i have some problem after reboot it showing like this error .. end -request: i/o error / dev hdb, sector 2566830 cant excute : /etc/init.d/rc No more process /etc in this run level any one know .. plz reply soon ... coz i 'm working as data center (2 Replies)
Discussion started by: coolboys
2 Replies

3. OS X (Apple)

cannot excute binary file

Hi, I am a new user of Mac OSX 10.7 (Lion). I am trying to compile a program and followed steps as: 1: qmake program_name.pro Not to mention I have installed qt and program compile perfectly without error and create a Makefile. 2: make Again everything worked fine and I got an executable... (1 Reply)
Discussion started by: karun25u
1 Replies

4. Shell Programming and Scripting

Executing expect script giving message as bad interpreter: Permission denied

Hi Gurus, I am new to scripting and needs your help in expect script used for telnet. I wrote a simple script as #!/usr/bin/expect-5.43 -f spawn telnet localhost 2233 expect "password:" send "secret\r" send "i data.cnbc.com\r" send "exit\r" expect eof When I am trying to execute... (2 Replies)
Discussion started by: niks_yv
2 Replies

5. Shell Programming and Scripting

Permission denied while executing rsh

Hi All, I have two servers, say server1 and server2. I have put the entries of both servers in /.rhosts file of both servers. So, when I tried to run following from server1- rsh server2 "ls" Permission denied was printed on console. Can anyone help me out? Regards, akash mahakode (4 Replies)
Discussion started by: akash_mahakode
4 Replies

6. Shell Programming and Scripting

How to excute an awk file

Hi All, Greetings. I am working with an awk file say "Test.awk". My Input file is say "test" I am executing the awk file using awk -f Test.awk test I am new to awk. I wanted to know how can we execute the above awk command from a ksh file. Please help me on this. Thanks in advance!! (9 Replies)
Discussion started by: dinesh1985
9 Replies

7. Shell Programming and Scripting

Excute file then..

I have a text file with only the command: MyTextFile: ls -l in it.. So in my sript im trying.. sh MyTextFile.txt >> MyTextFile.txt Just to overwrite and replace the command with its output. sh MyTextFile.txt 2>1 MyTextFile.txt isnt redirecting either.. :( Im getting the... (3 Replies)
Discussion started by: omgsomuchppl
3 Replies

8. Shell Programming and Scripting

is there any way to excute script every N seconds?

Hello i have script that show me stuff , i need to excute this script every N seconds , is there any way to do it with one liner ? ( mybe perl ) thanks (7 Replies)
Discussion started by: umen
7 Replies

9. UNIX for Dummies Questions & Answers

Why ' Permission denied' when executing a command?

Hi All, When I execute a command on Unix and it says 'Permission denied'. What could be the reason and how can it be resolved? Many thanks, David (2 Replies)
Discussion started by: david_wang
2 Replies

10. UNIX for Advanced & Expert Users

help! can't excute

I can't excute any commands in /usr/bin when I try to excute commands in /usr/bin the error message is displayed " No Such device or address" Can you Help? Thanks in Advance (6 Replies)
Discussion started by: hassan2
6 Replies
Login or Register to Ask a Question