标签:style io ar color os 使用 sp for on
[root@localhost ~]# cat /root/testaabbccddee[root@localhost ~]# cat test.sh#!/bin/bashdeclare -i x=1for i in `cat /root/test`; doecho "value$x$count:=$i"let x++done[root@localhost ~]# bash test.shvalue1:=aavalue2:=bbvalue3:=ccvalue4:=ddvalue5:=ee
[root@localhost ~]# cat test.sh#!/bin/bashdeclare -i x=1for i in /tmp/*; doecho "value$x$count:=$i"let x++done[root@localhost ~]# bash test.shvalue1:=/tmp/test1value2:=/tmp/test2value3:=/tmp/test3value4:=/tmp/test
#/bin/bashfor (( a = 1,b=10; a <= 10; a++,b-- )); doecho "$a-$b"done
[root@localhost ~]# cat test.sh#!/bin/bashread -p "Enter a choice" choicecase ${choice:-b} ina) echo "a";;b) echo "b";;c) echo "b";;esac[root@localhost ~]# bash test.shEnter a choiceb
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=92x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=183x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=274x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=365x5=25 5x6=30 5x7=35 5x8=40 5x9=456x6=36 6x7=42 6x8=48 6x9=547x7=49 7x8=56 7x9=638x8=64 8x9=729x9=81#!/bin/bashdeclare -i i=1declare -i j=1while [[ $i -lt 10 ]]; dolet j=$iuntil [[ $j -gt 9 ]]; doecho -e -n "${i}x${j}=$[$i*$j]\t"let j++donelet i++echodone
9x9=818x8=64 8x9=727x7=49 7x8=56 7x9=636x6=36 6x7=42 6x8=48 6x9=545x5=25 5x6=30 5x7=35 5x8=40 5x9=454x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=363x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=272x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=181x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9#!/bin/bashdeclare -i i=9while [[ $i -gt 0 ]]; doj=$iuntil [[ $j -gt 9 ]]; doecho -e -n "${i}x${j}=$[$i*$j]\t"let j++doneecholet i--done
[root@localhost ~]# cat /tmp/test aa aa aa aa bb bb bb bb cc cc cc cc#!/bin/bashcount=1cat /tmp/test | while read line; doecho "Line $count:$line"let count++done#!/bin/bashcount=1while read line; doecho "Line $count:$line"let count++done < /tmp/test- 2个脚本的效果一样
Line 1:aa aa aa aaLine 2:bb bb bb bbLine 3:cc cc cc cc
[root@localhost ~]# cat test.sh#!/bin/bashfor i in {1..10}; doif [ $i -eq 5 ];thenbreakfiecho "$i"done[root@localhost ~]# bash test.sh1234
[root@localhost ~]# cat test.sh#!/bin/bashfor i in {1..15}; doif [[ $i -gt 1 ]] && [[ $i -lt 14 ]]; thencontinuefiecho "$i"done[root@localhost ~]# bash test.sh11415
标签:style io ar color os 使用 sp for on
原文地址:http://www.cnblogs.com/kwstars/p/bea6f8fb74b164593333109b015934a2.html