batch file的label与shell的函数比较

1 batch file
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]@echo off 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
echo 调用前 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
echo 调用子过程 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
call :sub
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
echo 调用后 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
Goto end
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
:sub 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
echo 子过程调用中
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
goto :eof 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
:end
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
echo 退出
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
Pause 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
exit
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
注意:
label用:来定义,相当于程序块,也可以认为是函数,使用goto跳转到label。
如果使用call来调用label且label前仍有:,此时此label实际上被转化为子batch file。此时lable中的goto :eof仅表示推出子batch file,不是退出整个batch file。
2 shell file
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]#!/bin/bash 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]function quit {
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]   
exit
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]}  
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]function e {
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]    
echo $1 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]}  
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]e Hello
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]e World
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]quit
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
echo foo 
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]function afunc
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]{
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]  
echo "alice: $*"
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]  
echo "$0: $1 $2 $3 $4"
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]  
echo "$# arguments"
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]  local var1
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]  var1
="in function"
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]  
echo var1: $var1
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]  
return $?
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]}
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]var1
=globalvar
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]afunc a b c d e f
WindowsBatch与LinuxShell比较[batchfile之label与shell之函数]
echo $var1
注意:
定义时不用指定参数,调用时直接用$1,$2...来访问参数。
function 中可以使用local来屏蔽全局变量。

3完!

相关文章: