拓展閱讀
linux Shell 命令行-03-array 數(shù)組
linux Shell 命令行-04-operator 操作符
linux Shell 命令行-05-test 驗(yàn)證是否符合條件
linux Shell 命令行-06-flow control 流程控制
linux Shell 命令行-07-func 函數(shù)
linux Shell 命令行-08-file include 文件包含
linux Shell 命令行-09-redirect 重定向
基本輸出
echo
echo [-e] 字符串
printf
類似于 C 的 printf() 函數(shù)
printf 格式化字符串 [參數(shù)...]
test 測(cè)試條件是否成立
數(shù)字
- test_num.sh
#!/bin/bash
num1=100
num2=100
if test $[num1] -eq $[num2]
then
echo '兩個(gè)數(shù)相等!'
else
echo '兩個(gè)數(shù)不相等!'
fi
運(yùn)行
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh test_num.sh
兩個(gè)數(shù)相等!
字符串
- test_str.sh
#!/bin/bash
num1="runoob"
num2="runoob"
if test num1=num2
then
echo '兩個(gè)字符串相等!'
else
echo '兩個(gè)字符串不相等!'
fi
運(yùn)行
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh test_str.sh
兩個(gè)字符串相等!
文件
- test_file.sh
#!/bin/bash
if test -e /bin/bash
then
echo '文件已存在!'
else
echo '文件不存在!'
fi
運(yùn)行
houbinbindeMacBook-Pro:shell houbinbin$ /bin/sh test_file.sh
文件已存在!
本文由博客一文多發(fā)平臺(tái) OpenWrite 發(fā)布!