linux設置sh腳本命令
㈠ linux下通過 sh 打開一個程序,如何編寫sh腳本。
首先你要讓文件有能夠執行的許可權,比如你的文件是a.sh那麼你可以chmod+xa.sh然後運行文件就可以了./a.sh這樣運行是a.sh在當前工作目錄,如果文件沒在當前目錄,那麼就需要用絕對路徑來執行,比如/opt/a.sh/opt/test/a.sh
㈡ linux里sh命令是做什麼的詳解!
sh就是shell簡寫,就是unix下的腳本語言。
相當於windows下的dos命令
一般情況下環境變數是設置好的,不需要在shell腳本前加上sh,可以直接./a.sh執行的。
㈢ linux 如何開機自動運行sh腳本
要開機 運行只需將它加入到 rc.local ,一般為/etc/rc.d/rc.local 在其中加入以下行:sh /path/to/test.sh使用linux全局變數$?可以確定是否執行,如if [$? eq 0] the,echo "succeed!fi。
㈣ Linux怎麼將腳本sh製作為命令mtab
linux添加管理自定義命令
方法一:簡單的命令使用 alias 起別名 www.2cto.com
編輯所用的 shell 配置文件,如 bash 的 .bashrc,zsh 的 .zshrc,如加入:
alias ws="cd ~/workspace"
重載該配置文件使更改生效,如source .bashrc。在任意位置輸入ws,即可 cd 到 workspace 目錄。
www.2cto.com
如果有很多 alias 命令,可單獨定義一個文件存放,參考 .bashrc中 的一段說明:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
如果有多個shell,這種方法更方便管理,只需要將這個文件添加到各shell配置文件中即可。
方法二:將可執行文件目錄加入PATH
1、創建存放自定義命令的目錄,如my_cmd
2、將該目錄加入path中
編輯所用的 shell 配置文件,如 bash 的 .bashrc,zsh 的 .zshrc,加入
PATH=$PATH:~/my_cmd
也可以將該命令添加到方法一中單獨創建的自定義命令存放文件中
3、重載該配置文件使更改生效,如 source .bashrc
4、將自定義的可執行程序放入 my_cmd 中,在 shell 就可以直接執行了
方法三:綜合上述方法管理自定義命令
1、編輯所用的 shell 配置文件,如 bash 的 .bashrc,zsh 的 .zshrc,加入:
if [ -f ~/shellrc ]; then
. ~/shellrc
fi
2、創建 shellrc,加入對 shell 配置文件的改動,如:
PATH=$PATH:~/my_cmd
alias ws="cd ~/workspace"
簡單的命令如 alias,放入shellrc。可執行文件放入my_cmd。
㈤ Linux配置開機自啟動執行腳本有哪些方法
設置test.sh為開機要啟動的腳本
[root@oldboy scripts]# vim /server/scripts/test.sh
[root@oldboy scripts]# cat /server/scripts/ test.sh
#!/bin/bash
/bin/echo $(/bin/date +%F_%T) >> /tmp/ test.log
方法一:修改/etc/rc.local
[root@oldboy ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Mar 30 10:50 /etc/rc.local -> rc.d/rc.local
修改/etc/rc.local文件
[root@oldboy scripts]# tail -n 1 /etc/rc.local
/bin/bash /server/scripts/test.sh >/dev/null 2>/dev/null
重啟系統,查看結果
[root@oldboy ~]# cat /tmp/test.log
2018-03-30_12:00:10
方法二:chkconfig管理
刪除掉方法一的配置
[root@oldboy ~]# vim /etc/init.d/test
#!/bin/bash
# chkconfig: 3 88 88
/bin/bash /server/scripts/test.sh >臘敏/dev/null 2>/dev/null
[root@oldboy ~]# chmod +x /etc/init.d/test
添加到chkconfig,開機自啟動
[root@oldboy ~]# chkconfig --add test
[root@oldboy ~]# chkconfig --list test
test 0:off 1:off 2:off 3:on 4:off 5:off 6:off
重啟系統,查看結果
[root@oldboy ~]# cat /tmp/test.log
2018-03-30_12:00:10
2018-03-30_12:33:20
操作成功
關閉開機啟動
[root@oldboy ~]# chkconfig test off
[root@oldboy ~]# chkconfig --list test
test 0:off 1:off 2:off 3:off 4:off 5:off 6:off
從chkconfig管理中刪攜局神除辯虧test
[root@oldboy ~]# chkconfig --list test
test 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@oldboy ~]# chkconfig --del test
[root@oldboy ~]# chkconfig --list test
service test supports chkconfig, but is not referenced in any runlevel (run
'chkconfig --add test')
㈥ 怎麼在linux下創建一個可運行腳本
步驟:
1.新建一個.sh文件,touch test.sh
(6)linux設置sh腳本命令擴展閱讀:
Linux是一套免費使用和自由傳播的類Unix操作系統,是一個基於POSIX和UNIX的多用戶、多任務、支持多線程和多CPU的操作系統。它能運行主要的UNIX工具軟體、應用程序和網路協議。它支持32位和64位硬體。Linux繼承了Unix以網路為核心的設計思想,是一個性能穩定的多用戶網路操作系統。
Linux操作系統誕生於1991 年10 月5 日(這是第一次正式向外公布時間)。Linux存在著許多不同的Linux版本,但它們都使用了Linux內核。Linux可安裝在各種計算機硬體設備中,比如手機、平板電腦、路由器、視頻游戲控制台、台式計算機、大型機和超級計算機。
嚴格來講,Linux這個詞本身只表示Linux內核,但實際上人們已經習慣了用Linux來形容整個基於Linux內核,並且使用GNU工程各種工具和資料庫的操作系統。
腳本(Script)是使用一種特定的描述性語言,依據一定的格式編寫的可執行文件,又稱作宏或批處理文件。
Linux系統的shell作為操作系統的外殼,為用戶提供使用操作系統的介面。它是命令語言、命令解釋程序及程序設計語言的統稱。
shell是用戶和Linux內核之間的介面程序,如果把Linux內核想像成一個球體的中心,shell就是圍繞內核的外層。當從shell或其他程序向Linux傳遞命令時,內核會做出相應的反應。
shell是一個命令語言解釋器,它擁有自己內建的shell命令集,shell也能被系統中其他應用程序所調用。用戶在提示符下輸入的命令都由shell先解釋然後傳給Linux核心。