Difference between executing a shell using sh and .


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Difference between executing a shell using sh and .
# 1  
Old 06-21-2007
Difference between executing a shell using sh and .

Is there any difference in executing the shell using sh and . and ./.

I had a shell script and i observed that anyone is ale to execute the script eith sh even without having the execute permission.how is so?
# 2  
Old 06-21-2007
You can execute a read-only script by redirecting it to sh:
Code:
sh < readonly.sh
# or 
cat readonly.sh | sh

# 3  
Old 06-21-2007
Quote:
Originally Posted by soumyo_das
Is there any difference in executing the shell using sh and . and ./.

If you use sh SCRIPT, you are running a separate process.

If you use . SCRIPT, you are running the script in the current shell environment, and it can change variables, functions, etc., in the current shell.

I don't know what you mean by ./.

Quote:
I had a shell script and i observed that anyone is ale to execute the script eith sh even without having the execute permission.how is so?

If the shell can read the file, it can interpret it, i.e., execute the instructions it contains.

Execute permission is only needed to execute the file as a command.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference in executing the script

Hi Team, a silly question. Let's say i have a script called xyz.ksh what is the difference in executing the script as follows? ./xyz.ksh ksh xyz.ksh Thanks (2 Replies)
Discussion started by: kmanivan82
2 Replies

2. Shell Programming and Scripting

Executing a shell script using sh

Platform : Solaris 10, RHEL 5.4, OEL 6 I've noticed that some of my colleagues execute scripts by typing sh before the script name sh myscript.shI always execute a script by typing the script name and typing enter provided PATH variable has . (current directory) in it myscript.sh (and... (1 Reply)
Discussion started by: John K
1 Replies

3. UNIX for Dummies Questions & Answers

Why is this shell not executing?

%touch nu %cat nu who | wc -l %chmod +x nu %nu nu: Command not found (5 Replies)
Discussion started by: Shaun74
5 Replies

4. Shell Programming and Scripting

What is the difference executing a script with . in the front versus not putting a "."

Hi All, I know this has been discussed a lot but still I need some more answers. I am running this is ksh on AIX 5.3 I believe putting a "." in front of the script will start a new shell, is that correct?? I have a script which override some PATH variables and it does not do that... (3 Replies)
Discussion started by: Hangman2
3 Replies

5. Programming

c executing shell problem

Hello im geting error here: #include <stdlib.h> #include <stdio.h> using namespace std; int main (int argc, char *argv) { char user; string command; cin << user; command = printf ("grep '%s' /etc/shadow", user); system (command.c_str()); } return 0; } it should search shadow... (6 Replies)
Discussion started by: velniaszs
6 Replies

6. Shell Programming and Scripting

Difference in Executing a Script

Can anyone tell me the difference between the following execution ways: 1) . ./filename 2) ./filename Also when to use the either. (8 Replies)
Discussion started by: Shivdatta
8 Replies

7. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

8. UNIX for Dummies Questions & Answers

Executing Shell Scripts

Hi, I'm pretty new to Unix and I just have a question concerning making a script executable without putting the "sh" command before it. In case it makes the difference I am on an Apple computer using the Terminal. Anyway here is the little test code I wrote followed by the commands I took to try... (1 Reply)
Discussion started by: BuyoCat
1 Replies

9. UNIX for Advanced & Expert Users

Shell script is not executing

Hi, I am trying to execute the below shell script: script name(ss1). ss1 was given permission - 744 before executing. name: ss1 #ss1 #usage:ss1 ls who pwd :wq I tried to execute $ss1 (Enter) Its not executing.... It says that ss1 is not found: echo $SHELL. The o/put i got is... (5 Replies)
Discussion started by: dreams5617
5 Replies

10. UNIX for Dummies Questions & Answers

executing in parent shell.

I have a script that I want to run in my current shell. I know that if I start it with a period ie '. myprogram' that this will cause it to run in my current shell instead of starting a new shell for it. What if I forgot to put the period. Is there some command that I can put in 'myprogram'... (1 Reply)
Discussion started by: Alan Bird
1 Replies
Login or Register to Ask a Question