Linux declare命令、Linux tail 命令
前些天發(fā)現(xiàn)了一個巨牛的人工智能學(xué)習(xí)網(wǎng)站,通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家。點擊跳轉(zhuǎn)到教程。
Linux declare命令用于聲明 shell 變量。
declare為shell指令,在第一種語法中可用來聲明變量并設(shè)置變量的屬性([rix]即為變量的屬性),在第二種語法中可用來顯示shell函數(shù)。若不加上任何參數(shù),則會顯示全部的shell變量與函數(shù)(與執(zhí)行set指令的效果相同)。
語法
declare [+/-][rxi][變量名稱=設(shè)置值] 或 declare -f[+/-][rxi][變量名稱=設(shè)置值] 或 declare -f參數(shù)說明:
- +/- "-"可用來指定變量的屬性,"+"則是取消變量所設(shè)的屬性。
- -f 僅顯示函數(shù)。
- r 將變量設(shè)置為只讀。
- x 指定的變量會成為環(huán)境變量,可供shell以外的程序來使用。
- i [設(shè)置值]可以是數(shù)值,字符串或運算式。
實例
聲明整數(shù)型變量
# declare -i ab //聲明整數(shù)型變量 # ab=56 //改變變量內(nèi)容 # echo $ab //顯示變量內(nèi)容 56 # ab=56 //改變變量內(nèi)容 # echo $ab //顯示變量內(nèi)容 56改變變量屬性
# declare -i ef //聲明整數(shù)型變量 # ef=1 //變量賦值(整數(shù)值) # echo $ef //顯示變量內(nèi)容 1 # ef="wer" //變量賦值(文本值) # echo $ef 0 # declare +i ef //取消變量屬性 # ef="wer" # echo $ef wer # ef=1 //變量賦值(整數(shù)值) # echo $ef //顯示變量內(nèi)容 1 # ef="wer" //變量賦值(文本值) # echo $ef 0 # declare +i ef //取消變量屬性 # ef="wer" # echo $ef wer設(shè)置變量只讀
# declare -r ab //設(shè)置變量為只讀 # ab=88 //改變變量內(nèi)容 -bash: ab: 只讀變量 # echo $ab //顯示變量內(nèi)容 56 # ab=88 //改變變量內(nèi)容 -bash: ab: 只讀變量 # echo $ab //顯示變量內(nèi)容 56聲明數(shù)組變量
# declare -a cd='([0]="a" [1]="b" [2]="c")' //聲明數(shù)組變量 # echo ${cd[1]} b //顯示變量內(nèi)容# echo ${cd[@]} //顯示整個數(shù)組變量內(nèi)容 a b c # echo ${cd[1]} b //顯示變量內(nèi)容# echo ${cd[@]} //顯示整個數(shù)組變量內(nèi)容 a b c顯示函數(shù)
# declare -f command_not_found_handle () { if [ -x /usr/lib/command-not-found ]; then/usr/bin/python /usr/lib/command-not-found -- $1;return $?;elseif [ -x /usr/share/command-not-found ]; then/usr/bin/python /usr/share/command-not-found -- $1;return $?;elsereturn 127;fi;fi } command_not_found_handle () { if [ -x /usr/lib/command-not-found ]; then/usr/bin/python /usr/lib/command-not-found -- $1;return $?;elseif [ -x /usr/share/command-not-found ]; then/usr/bin/python /usr/share/command-not-found -- $1;return $?;elsereturn 127;fi;fi }?
-----------------------------------? 我 是 分 隔 線 ----------------------------------------
?
tail 命令可用于查看文件的內(nèi)容,有一個常用的參數(shù)?-f?常用于查閱正在改變的日志文件。
?
tail -f filename?會把 filename 文件里的最尾部的內(nèi)容顯示在屏幕上,并且不但刷新,只要 filename 更新就可以看到最新的文件內(nèi)容。
命令格式:
tail [參數(shù)] [文件] [參數(shù)] [文件]參數(shù):
- -f 循環(huán)讀取
- -q 不顯示處理信息
- -v 顯示詳細(xì)的處理信息
- -c<數(shù)目> 顯示的字節(jié)數(shù)
- -n<行數(shù)> 顯示行數(shù)
- --pid=PID 與-f合用,表示在進(jìn)程ID,PID死掉之后結(jié)束.
- -q, --quiet, --silent 從不輸出給出文件名的首部
- -s, --sleep-interval=S 與-f合用,表示在每次反復(fù)的間隔休眠S秒
實例
要顯示 notes.log 文件的最后 10 行,請輸入以下命令:
tail notes.log.log要跟蹤名為 notes.log 的文件的增長情況,請輸入以下命令:
tail -f notes.log-f notes.log此命令顯示 notes.log 文件的最后 10 行。當(dāng)將某些行添加至 notes.log 文件時,tail 命令會繼續(xù)顯示這些行。 顯示一直繼續(xù),直到您按下(Ctrl-C)組合鍵停止顯示。
顯示文件 notes.log 的內(nèi)容,從第 20 行至文件末尾:
tail +20 notes.log+20 notes.log顯示文件 notes.log 的最后 10 個字符:
tail -c 10 notes.log-c 10 notes.log?
總結(jié)
以上是生活随笔為你收集整理的Linux declare命令、Linux tail 命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [导入]Netron研究(二)----容
- 下一篇: TD-SCDMA成为我国通信行业标准