shell总结(0基础入门)
?
一、簡介
shell是用戶和操作系統交互的命令行解釋器。
shell有很多種:
bash、csh、sh、ksh、、、
?
我們等了linux時看到的命令行就是一個bash。?
?
二、第一個腳本:
[root@linux1 script]# vim first.sh
#!/bin/bash
#auther:xiaofan
#time:2016.10.4
#井號是注釋
echo "hello word"
?
執行腳本:
方法1:
[root@linux1 script]# bash first.sh
hello word
[root@linux1 script]# sh first.sh
hello word
方法2:
[root@linux1 script]# chmod +x first.sh
[root@linux1 script]# ./first.sh
hello word
?
查看腳本執行的過程:
[root@linux1 script]# sh -x first.sh
+ echo 'hello word'
hello word
?
三、變量
?
變量分為兩大類:
局部變量:需要自己定義。
環境變量:系統自帶的。
?
變量定義:
變量名稱=變量值
?
調用自定義變量:
[root@linux1 script]# name="xiaofan"
[root@linux1 script]# echo "my name is $name"
my name is xiaofan
[root@linux1 script]# echo my name is $name
my name is xiaofan
[root@linux1 script]# echo 'my name is $name' ? #注意單引號是不會解釋變量的
my name is $name
?
?
常用的系統變量:
[root@linux1 script]# cat t1.sh
#!/bin/bash
echo $0 ? ? ?#當前程序名
echo $1 #程序的第一個參數
echo $* #程序的所有參數名
echo $# #當前程序的參數個數
echo $? ? ? ? #程序執行的返回狀態
echo $PATH ? ?#系統環境變量的路徑
echo $PWD ? ? ?#當前目錄
echo $UID ? ? ? ?#當前用的id
[root@linux1 script]# sh t1.sh t1 t2
t1.sh
t1
t1 t2
2
0
/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/root/bin
/script
0
?
?
三、腳本輸出有顏色的字體:
\033[32m ?和 \033[0m ?之間的字體會變成綠色
\033[32m ?和 \033[1m ?下面的所有的字體會變成綠色
\033[31m ?和 \033[0m ?之間的字體會變成紅色
?
?
轉載于:https://www.cnblogs.com/fanxuanhui-linux/p/5931503.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的shell总结(0基础入门)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 传感技术复习笔记(10)——光纤传感器
- 下一篇: PR开场片头视频模板 多帧城市闪点社交媒