标签:style io ar color os 使用 sp for on
[root@localhost ~]# cat /root/test
aa
bb
cc
dd
ee
[root@localhost ~]# cat test.sh
#!/bin/bash
declare -i x=1
for i in `cat /root/test`; do
echo "value$x$count:=$i"
let x++
done
[root@localhost ~]# bash test.sh
value1:=aa
value2:=bb
value3:=cc
value4:=dd
value5:=ee
[root@localhost ~]# cat test.sh
#!/bin/bash
declare -i x=1
for i in /tmp/*; do
echo "value$x$count:=$i"
let x++
done
[root@localhost ~]# bash test.sh
value1:=/tmp/test1
value2:=/tmp/test2
value3:=/tmp/test3
value4:=/tmp/test
#/bin/bash
for (( a = 1,b=10; a <= 10; a++,b-- )); do
echo "$a-$b"
done
[root@localhost ~]# cat test.sh
#!/bin/bash
read -p "Enter a choice" choice
case ${choice:-b} in
a) echo "a";;
b) echo "b";;
c) echo "b";;
esac
[root@localhost ~]# bash test.sh
Enter a choice
b
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x6=36 6x7=42 6x8=48 6x9=54
7x7=49 7x8=56 7x9=63
8x8=64 8x9=72
9x9=81
#!/bin/bash
declare -i i=1
declare -i j=1
while [[ $i -lt 10 ]]; do
let j=$i
until [[ $j -gt 9 ]]; do
echo -e -n "${i}x${j}=$[$i*$j]\t"
let j++
done
let i++
echo
done
9x9=81
8x8=64 8x9=72
7x7=49 7x8=56 7x9=63
6x6=36 6x7=42 6x8=48 6x9=54
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
#!/bin/bash
declare -i i=9
while [[ $i -gt 0 ]]; do
j=$i
until [[ $j -gt 9 ]]; do
echo -e -n "${i}x${j}=$[$i*$j]\t"
let j++
done
echo
let i--
done
[root@localhost ~]# cat /tmp/test aa aa aa aa bb bb bb bb cc cc cc cc
#!/bin/bash
count=1
cat /tmp/test | while read line; do
echo "Line $count:$line"
let count++
done
#!/bin/bash
count=1
while read line; do
echo "Line $count:$line"
let count++
done < /tmp/test
- 2个脚本的效果一样
Line 1:aa aa aa aa
Line 2:bb bb bb bb
Line 3:cc cc cc cc
[root@localhost ~]# cat test.sh
#!/bin/bash
for i in {1..10}; do
if [ $i -eq 5 ];then
break
fi
echo "$i"
done
[root@localhost ~]# bash test.sh
1
2
3
4
[root@localhost ~]# cat test.sh
#!/bin/bash
for i in {1..15}; do
if [[ $i -gt 1 ]] && [[ $i -lt 14 ]]; then
continue
fi
echo "$i"
done
[root@localhost ~]# bash test.sh
1
14
15
标签:style io ar color os 使用 sp for on
原文地址:http://www.cnblogs.com/kwstars/p/bea6f8fb74b164593333109b015934a2.html