Whats the difference between running a shell script as ./script.sh and sh script.sh

Posted by Ritesh M Nayak on Stack Overflow See other posts from Stack Overflow or by Ritesh M Nayak
Published on 2010-03-18T07:28:59Z Indexed on 2010/03/18 7:31 UTC
Read the original article Hit count: 831

Filed under:
|
|

I have a script that looks like this

#!/bin/bash

function something() {
 echo "hello world!!"
}

something | tee logfile 

I have set the execute permission on this file and when I try running the file like this

 $./script.sh

it runs perfectly fine, but when I run it on the command line like this

$sh script.sh 

It throws up an error. Why does this happen and what are the ways in which I can fix this.

© Stack Overflow or respective owner

Related posts about unix

Related posts about scripting