LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2010, 12:05 AM   #1
shravee
Member
 
Registered: Sep 2009
Posts: 84

Rep: Reputation: 16
Post are they same " sh execution " and " ./ execution "


hi ,

i created a script file named myscript.sh

i ran this by typing sh myscript.sh and i got my output

but,

when i tried to execute by typing ./myscript.sh i received permission denied error
i gave permission as chmod 777 myscript.sh
then i executed by typing ./myscript.sh . It worked fine

so i wanted to know whether using sh and ./ with permissions are same.. ?



or did it work for only this.. are there any differences ???


regards
shravee

Last edited by shravee; 04-17-2010 at 12:07 AM.
 
Old 04-17-2010, 01:11 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
I think sh myscript.sh starts a sh shell which then runs the script (so two processes) whereas ./myscript.sh runs the script in a subprocess (so one process). You can find out by putting a sleep in your script (so it "runs" for a long enough for you to ...) use pstree to see the process tree. Another difference is that sh myscript.sh runs the script using the sh shell whereas ./myscript.sh runs the script respecting any #!<interpreter path> on the first line of your script. Even if sh (/bin/sh?) is a symbolic link to bash (/bin/bash?) bash behaves differently depending on the name it is called by.

If you want to run your script simply by myscript.sh then you need to add "." (without the quotes) to your $PATH.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Execution of a script to be stopped after "x" minutes of time YSE Linux - Newbie 3 10-01-2008 12:00 AM
net working eth0 eth1 wlan0 "no connection" "no LAN" "no wi-fi" Cayitano Linux - Newbie 5 12-09-2007 07:11 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Lost Execution rights of "chmod" arkus Linux - General 2 10-05-2004 09:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration