!!!!!!!!!!!!!!!!注意空格不可以随便用额,会恶心屎你的。。。
**************************************
如何计算传递进来的参数 ?
$#
***************************
如何在脚本中获取脚本名称 ?
$0
******************************************
如何检查之前的命令是否运行成功 ?
$?
0为真 1 为假
****************************************
每个脚本开始的 #!/bin/sh 或 #!/bin/bash 表示什么意思 ?
这一行说明要使用的 shell。#!/bin/bash 表示脚本使用 /bin/bash。对于 python 脚本,就是 #!/usr/bin/python。(LCTT译注:这一行称之为释伴行。)
********************************88
判断文件是否存在
if [ -f filename ]
then
fi
**********************************
整数加法
declare -i a=3 b=4
declare -i c=$a+$b
echo $c
-i integer
-a array
-f function
-r readonly
*************************************************
for循环
1.
for i in `seq 10`
do
echo $i
done
2.
for ((i=0;i<10;i++))
do
echo $i
done
注意:2比1要好,因为seq对于大数就挂了,会跑死的,建议用第二种格式
************************************************8
while 循环
i=0
while($i<10)
do
echo $i
i=$(($i+1))
done
********************************
函数
#!/bin/bash
function fun()
{
for name in $@
do
echo "Hello ${name}"
done
}
fun xx yy
*****************************************************
写出输出数字 0 到 100 中 3 的倍数(0 3 6 9 …)的命令 ?
for i in{0..100..3};do echo $i;done
或
for(( i=0; i<=100; i=i+3));do echo "Welcome $i times";done
************************************
[ $a == $b ] 和 [ $a -eq $b ] 有什么区别?
[ $a == $b ] - 用于字符串比较
[ $a -eq $b ] - 用于数字比较
8*********************************************
如何打印数组的所有元素 ?
echo ${array[@]}
*******************************************
如何移除数组中索引为 2 的元素 ?
unset array[2]
****************************
read 接受用户输入
read -p "plese input a string: " str
>hello world
echo $str
<hello world
**************************************
如何计算传递进来的参数 ?
$#
***************************
如何在脚本中获取脚本名称 ?
$0
******************************************
如何检查之前的命令是否运行成功 ?
$?
0为真 1 为假
****************************************
每个脚本开始的 #!/bin/sh 或 #!/bin/bash 表示什么意思 ?
这一行说明要使用的 shell。#!/bin/bash 表示脚本使用 /bin/bash。对于 python 脚本,就是 #!/usr/bin/python。(LCTT译注:这一行称之为释伴行。)
********************************88
判断文件是否存在
if [ -f filename ]
then
fi
**********************************
整数加法
declare -i a=3 b=4
declare -i c=$a+$b
echo $c
-i integer
-a array
-f function
-r readonly
*************************************************
for循环
1.
for i in `seq 10`
do
echo $i
done
2.
for ((i=0;i<10;i++))
do
echo $i
done
注意:2比1要好,因为seq对于大数就挂了,会跑死的,建议用第二种格式
************************************************8
while 循环
i=0
while($i<10)
do
echo $i
i=$(($i+1))
done
********************************
函数
#!/bin/bash
function fun()
{
for name in $@
do
echo "Hello ${name}"
done
}
fun xx yy
*****************************************************
写出输出数字 0 到 100 中 3 的倍数(0 3 6 9 …)的命令 ?
for i in{0..100..3};do echo $i;done
或
for(( i=0; i<=100; i=i+3));do echo "Welcome $i times";done
************************************
[ $a == $b ] 和 [ $a -eq $b ] 有什么区别?
[ $a == $b ] - 用于字符串比较
[ $a -eq $b ] - 用于数字比较
8*********************************************
如何打印数组的所有元素 ?
echo ${array[@]}
*******************************************
如何移除数组中索引为 2 的元素 ?
unset array[2]
****************************
read 接受用户输入
read -p "plese input a string: " str
>hello world
echo $str
<hello world