拓展阅读
基本输出
echo
echo [-e] 字符串
printf
类似于 C 的 printf() 函数
printf 格式化字符串 [参数...]
test 测试条件是否成立
数字
- test_num.sh
#!/bin/bash
num1=100
num2=100
if test $[num1] -eq $[num2]
then
echo '两个数相等!'
else
echo '两个数不相等!'
fi
运行
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh test_num.sh
两个数相等!
字符串
- test_str.sh
#!/bin/bash
num1="runoob"
num2="runoob"
if test num1=num2
then
echo '两个字符串相等!'
else
echo '两个字符串不相等!'
fi
运行
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh test_str.sh
两个字符串相等!
文件
- test_file.sh
#!/bin/bash
if test -e /bin/bash
then
echo '文件已存在!'
else
echo '文件不存在!'
fi
运行
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh test_file.sh
文件已存在!
本文由博客一文多发平台 OpenWrite 发布!
點擊查看更多內(nèi)容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦