拓展閱讀
linux Shell 命令行-00-intro 入門介紹
linux Shell 命令行-02-var 變量
linux Shell 命令行-03-array 數(shù)組
linux Shell 命令行-04-operator 操作符
linux Shell 命令行-05-test 驗(yàn)證是否符合條件
linux Shell 命令行-06-flow control 流程控制
linux Shell 命令行-07-func 函數(shù)
linux Shell 命令行-08-file include 文件包含
linux Shell 命令行-09-redirect 重定向
shell
Shell 是一個(gè)用 C 語言編寫的程序,它是用戶使用 Linux 的橋梁。
Shell 既是一種命令語言,又是一種程序設(shè)計(jì)語言。
Shell 是指一種應(yīng)用程序,這個(gè)應(yīng)用程序提供了一個(gè)界面,用戶通過這個(gè)界面訪問操作系統(tǒng)內(nèi)核的服務(wù)。
Ken Thompson 的 sh 是第一種 Unix Shell,Windows Explorer 是一個(gè)典型的圖形界面 Shell。
Shell 腳本
Shell 腳本(shell script),是一種為 shell 編寫的腳本程序。
業(yè)界所說的 shell 通常都是指 shell 腳本,但讀者朋友要知道,shell 和 shell script 是兩個(gè)不同的概念。
由于習(xí)慣的原因,簡潔起見,本文出現(xiàn)的 "shell編程" 都是指 shell 腳本編程,不是指開發(fā) shell 自身。
Shell類型
- Bourne Shell(/usr/bin/sh 或 /bin/sh)
- Bourne Again Shell(/bin/bash)
- C Shell(/usr/bin/csh)
- K Shell(/usr/bin/ksh)
- Root Shell(/sbin/sh)
通常,我們不區(qū)分 Bourne Shell
和 Bourne Again Shell
Shell 實(shí)戰(zhàn)測試
創(chuàng)建 hello.sh
houbinbindeMacBook-Pro:shell houbinbin$ pwd
/Users/houbinbin/code/shell
houbinbindeMacBook-Pro:shell houbinbin$ vi hello.sh
編輯 hello.sh
的內(nèi)容
#!/bin/bash
echo "hello world!"
簡單解釋
hello.sh
的含義
#!
告訴操作系統(tǒng)要使用哪個(gè)解釋器,echo
用于在窗口中打印信息。
運(yùn)行
- 運(yùn)行
hello.sh
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh hello.sh
hello world!
- 另一種運(yùn)行方式
houbinbindeMacBook-Pro:shell houbinbin$ ./hello.sh
-bash: ./hello.sh: Permission denied
houbinbindeMacBook-Pro:shell houbinbin$ chmod +x ./hello.sh
houbinbindeMacBook-Pro:shell houbinbin$ ./hello.sh
hello world!
從輸入讀取
hello_name.sh
#!/bin/bash
# 作者:houbinbin
echo "請輸入您的名字?"
read NAME
echo "您好,$NAME!"
- 運(yùn)行
houbinbindeMacBook-Pro:shell houbinbin$ vi hello_name.sh
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh hello_name.sh
請輸入您的名字?
houbinbin
您好,houbinbin!
houbinbindeMacBook-Pro:shell houbinbin$
參考資料
https://www.runoob.com/linux/linux-shell.html
Shell 中文教程文章來源:http://www.zghlxwxcb.cn/news/detail-838153.html
Shell 中文教程
本文由博客一文多發(fā)平臺 OpenWrite 發(fā)布!文章來源地址http://www.zghlxwxcb.cn/news/detail-838153.html
到了這里,關(guān)于linux Shell 命令行-01-intro 入門介紹的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!