当前位置:Linux教程 - Linux文化 - sh xxx.sh 与 ./xxx.sh 的区别?

sh xxx.sh 与 ./xxx.sh 的区别?


>>> 此贴的回复 >> 首先, ./file.sh 需要有 x permission, 而sh file.sh 不需要. 如果 file.sh 裡面有指定 interpreter (在第一行用 #!/path) 的話, 兩者都會用指定的 interpreter 作 sub shell 去執行 file.sh 裡面的命令. 但如果沒有指定 interpreter, 那 sh file.sh 則會用 sh 作 sub shell. 至於 ./file.sh , 那要看你當前的 shell 是甚麼類型的: 有的 shell 用當前的 shell 作 sub shell, 有些則指定預設的 shell 作 sub shell.

但無論如何, sub shell 的環境(如變量)是不會影響當前 shell 的.