linux系统shell知识点,linux shell 知识点
1.if語句
語法為:
if [ 條件表達式 ]; then
.....
fi
條件表達式類型:
文件表達式
if [ -f?file ]?如果文件存在 if [ -d ...?]?如果目錄存在 if [ -s file?]?如果文件存在且非空 if [ -r file]如果文件存在且可讀 if [ -w file]如果文件存在且可寫 if [ -x file]如果文件存在且可執行
整數變量表達式
if [ int1 -eq int2 ]?如果int1等于int2 if [ int1 -ne int2 ]?如果不等于if [ int1 -ge int2 ]如果>= if [ int1 -gt int2 ]如果> if [ int1 -le int2 ]如果<= if [ int1 -lt int2 ]如果<
字符串變量表達式
If[ $a = $b ]如果string1等于string2 字符串允許使用賦值號做等號 if[ $string1 !=$string2 ]如果string1不等于string2if?[ -n $string?]?如果string 非空(非0),返回0(true)if[ -z $string]如果string 為空
if?[ $sting ]?如果string 非空,返回0 (和-n類似)
2.cocos2dx編寫android.mk文件時要列出需要編譯的.cpp .c文件,一個個查找非常麻煩,于是自己寫了個腳本,輸入命令就可以了。
用腳本之前,要先讓它生效:chmod +x getfilelist
用法:./getfilelist ../../Classes list.txt ##第一個參數為,shell腳本名,第二個為cpp文件的相對路徑,第三個為輸出文件
shell代碼:
#!/bin/sh
#help 提示
help()
{
echo !! Input error
echo USAGE: ./getfilelist 目錄名 輸出文件名
echo USAGE EXAMPLE: ./getfilelist ../Class list.txt
exit 0
}
getlist()
{
#第2個參數為空
if [ -z $2 ]; then
help
exit 1;
fi
#第一個參數為文件夾,則查找該路徑下的.cpp .c文件并輸出
if [ -d "$1" ]; then
find $1 -name "*.c"|sed 's/\.c/\.c \\/' > $2
#find $1 -name "*.cpp" >> $2
find $1 -name "*.cpp"|sed 's/\.cpp/\.cpp \\/' >> $2
echo "Success!"
else
echo "$1 not exits"
fi
}
#第一個參數為空
if [ -z $1 ]; then
help
exit 1;
fi
#參數遍歷
while [ -n "$1" ]; do
case $1 in
-h) help;shift 1;;#function help is called
-*) echo "error: no such option $1. -h for help";exit 1;;
*) getlist $1 $2;break;;
esac
done
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的linux系统shell知识点,linux shell 知识点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 鸿蒙初开踏青时主要内容,鸿蒙初开踏青时
- 下一篇: 敏捷方法简介