#!/bin/bash
#read:接收鍵盤輸入;-t 秒數:read命令會一直等待用戶輸入,使用此選項可以指定等待時間;-p:提示信息。
read -t 30 -p "please input the dir:" dir
#-d判斷是不是一個目錄
if [ -d "$dir" ]
then
echo "輸入的是目錄"
else
echo "輸入的不是目錄"
fi
#read:接收鍵盤輸入;-t 秒數:read命令會一直等待用戶輸入,使用此選項可以指定等待時間;-p:提示信息。
read -t 30 -p "please input the dir:" dir
#-d判斷是不是一個目錄
if [ -d "$dir" ]
then
echo "輸入的是目錄"
else
echo "輸入的不是目錄"
fi
2015-10-30
#!/bin/bash
#匹配出包含 sda5的行,取分區使用率這一列(樓主是第五列),用cut 按 "%"分割、取第一列的 參數取出根分區的使用率,賦值給變量test
test=$(df -h | grep "sda5" | awk '{print $5}' | cut -d '%' -f 1)
#如果變量test大于等于10,則輸出
if [ "$test" -ge '10' ]
then
echo "/ is null"
fi
#匹配出包含 sda5的行,取分區使用率這一列(樓主是第五列),用cut 按 "%"分割、取第一列的 參數取出根分區的使用率,賦值給變量test
test=$(df -h | grep "sda5" | awk '{print $5}' | cut -d '%' -f 1)
#如果變量test大于等于10,則輸出
if [ "$test" -ge '10' ]
then
echo "/ is null"
fi
2015-10-30
#!/bin/bash
#從環境變量中過濾出包含"USER"字符的行,結果為USER=root; 然后使用字符串截取命令cut,按 分隔符為"=",取第二列數據 的參數取出root值
test=$(env | grep "USER" | cut -d "=" -f 2)
# "=="是字符串判斷是否相等命令 ps:[]里的數據,兩邊需要加空格,否則會報命令錯誤
if [ "$test" == "root" ]
then
echo "this is my first shell code,go next"
fi
#從環境變量中過濾出包含"USER"字符的行,結果為USER=root; 然后使用字符串截取命令cut,按 分隔符為"=",取第二列數據 的參數取出root值
test=$(env | grep "USER" | cut -d "=" -f 2)
# "=="是字符串判斷是否相等命令 ps:[]里的數據,兩邊需要加空格,否則會報命令錯誤
if [ "$test" == "root" ]
then
echo "this is my first shell code,go next"
fi
2015-10-30
已采納回答 / onemoo
test1 和 test2 那兩句中,sed 和 后面的引號之間好像沒有空格:?sed 's/[0-9]//g'最后輸出結果時,result 錯打成 resulte了。
2015-10-17