UNIX Shell Script
出自KMU Wiki
(修訂版本間差異)
| 在2008年5月6日 (二) 19:18所做的修訂版本 (編輯) Cch (對話 | 貢獻) ←上一個 |
在2008年5月6日 (二) 19:20所做的修訂版本 (編輯) (撤銷) Cch (對話 | 貢獻) 下一個→ |
||
| 第2行: | 第2行: | ||
| === Variable === | === Variable === | ||
| - | <pre> | + | <pre>YOURVAR=some<br>echo $YOURVAR<br>echo ${YOURVAR}<br></pre> |
| - | YOURVAR=some | + | |
| - | echo $YOURVAR | + | |
| - | echo ${YOURVAR} | + | |
| - | </pre> | + | |
| <br> | <br> | ||
| === Flow control === | === Flow control === | ||
| - | <pre>if [ -f your_file ]; then | + | <pre>if [ -f your_file ]; then |
| + | echo "your_file exists | ||
| + | </pre> | ||
| <br> | <br> | ||
| - | <pre>for f in a b c | + | <pre> |
| + | for f in a b c | ||
| + | do | ||
| + | echo $f | ||
| + | done | ||
| + | </pre> | ||
| === Sub Program === | === Sub Program === | ||
| - | <pre>sub() | + | <pre> |
| + | sub() | ||
| + | { | ||
| + | echo $1 $2 $3 | ||
| + | } | ||
| + | sub X Y Z | ||
| + | </pre> | ||
| === Examples === | === Examples === | ||
| - | <pre>#!/bin/sh | + | <pre> |
| + | #!/bin/sh | ||
| + | exec <$1 | ||
| + | while read line | ||
| + | do | ||
| + | echo $line | ||
| + | done | ||
| + | </pre> | ||
| == C Shell == | == C Shell == | ||
在2008年5月6日 (二) 19:20所做的修訂版本
目錄 |
Bourne shell(sh)
Variable
YOURVAR=some<br>echo $YOURVAR<br>echo ${YOURVAR}<br>
Flow control
if [ -f your_file ]; then echo "your_file exists
for f in a b c
do
echo $f
done
Sub Program
sub()
{
echo $1 $2 $3
}
sub X Y Z
Examples
#!/bin/sh
exec <$1
while read line
do
echo $line
done
