Be careful of the blank in the following statements.
[[]] is a new feature in bash 3.0 for string comparision.
{{}} is a new feature in bash 3.0 for integer comparision.
so we can use "==, >=, <=" supersede "-eq, -gt, -lt"
Example:
if [[ "1" == "1" ]]; then
echo "1 equals 1"
fi
exit
$(()) expression can be used to do the operations with the integer, like
sum=$((1+1))
echo $sum
Then the output is 2.
Other way to the same result is:
declare -i sum=1+1 or sum=$[1+1]
others:
accounts=cat "/etc/passwd" | cut -d ":" -f1
for account in accounts
do
echo "$account"
done
if [ ! -e "somefile"]; then
fi
rm file
rmdir dir
touch file
echo $$ show curent pid
echo $? show the last return code.
export | cut -c 12- which will show 12+ chars
exercise:
cat /etc/passwd | sort -t ":" -k 3 sort according to 3rd column separated by ":"
uniq -c show the count which occurs multiply.
cat /etc/passwd | tr -d ':' remove ":"
本文详细介绍了bash3.0中的新特性,包括字符串比较、整数操作、文件操作等,通过实例展示了如何使用这些功能,并提供了练习题加深理解。
1089

被折叠的 条评论
为什么被折叠?



