[Unix / Linux Shell Tutorial - Lession8] Loops
- #!/bin/bash
- counter=1
- while [ $counter -le 10 ]
- do
- echo $counter
- ((counter++))
- done
- echo All done
- #!/bin/bash
- counter=1
- until [ $counter -gt 10 ]
- do
- echo $counter
- ((counter++))
- done
- echo All done
- #!/bin/bash
- names='Stan Kyle Cartman'
- for name in $names
- do
- echo $name
- done
- echo All done
- #!/bin/bash
- for value in {1..5}
- do
- echo $value
- done
- echo All done
- #!/bin/bash
- for value in {10..0..2}
- do
- echo $value
- done
- echo All done
- #!/bin/bash
- for value in $1/*.html
- do
- cp $value $1/$( basename -s .html $value ).php
- done
- #!/bin/bash
- for value in $1/*
- do
- used=$( df $1 | tail -1 | awk '{ print $5 }' | sed 's/%//' )
- if [ $used -gt 90 ]
- then
- echo Low disk space 1>&2
- break
- fi
- cp $value $1/backup/
- done
- #!/bin/bash
- for value in $1/*
- do
- if [ ! -r $value ]
- then
- echo $value not readable 1>&2
- continue
- fi
- cp $value $1/backup/
- done
- #!/bin/bash
- names='Kyle Cartman Stan Quit'
- PS3='Select character: '
- select name in $names
- do
- if [ $name == 'Quit' ]
- then
- break
- fi
- echo Hello $name
- done
- echo Bye
No comments:
Post a Comment