shell腳本的執行方法

1.
[root@usr001 ~]# echo 'userdir=pwd' >sun.sh
[root@usr001 ~]# cat sun.sh
userdir=pwd
[root@usr001 ~]# bash sun.sh
[root@usr001 ~]# sh sun.sh
[root@usr001 ~]# echo $userdirshell

[root@usr001 ~]# . sun.sh
[root@usr001 ~]# echo $userdir
/root
[root@usr001 ~]#bash

當前的黑窗口是一個shell,咱們稱之爲fathershell。sun.sh爲子ide

shell。使用bash或者sh不能將變量$userdir傳到fathershell中去code

,因此echo $userdir 什麼也不出現。當使用.或者source時能夠ip

將變量$userdir傳到fathershell中去,因此echo $userdir時會出it

現變量$userdir的值即pwd的值。class

2.shell腳本的執行一般可使用如下三種方式。
①bash script-name 或 sh script-name(推薦使用)
②path/script-name 或./script-name(當前路徑下執行腳本)
③source script-name 或 .空格 script-name變量

相關文章
相關標籤/搜索