Linux shell,Powershell与DOS shell的脚本差异

rm语句:注意rm, -f以及目标文件的空格

Bash

rm -f secure1.o secure2.o mpu.o secure.out tmp.s tmp1.s sjli_api.s sjli_api.o

DOS

del -Force secure1.o, secure2.o, mpu.o, secure.out, tmp.s, tmp1.s, sjli_api.s, sjli_api.o

Powershell

rm -Force secure1.o, secure2.o, mpu.o, secure.out, tmp.s, tmp1.s, sjli_api.s, sjli_api.o

变量定义

Bash

cflags="-rf16 -Xlib"
rflags="$cflags"

DOS

# 有局限性,不建议使用
set cflags="-rf16 -Xlib"
set rflags="$cflags$"

Powershell

$cflags="-rf16 -Xlib"
$rflags="$cflags"

字符查找

Bash

nmac -p normal.out | grep __HOSTLINK__

DOS

nmac -p normal.out | findstr __HOSTLINK__

Powershell

nmac -p normal.out | select-string -pattern __HOSTLINK__

正则表达

Bash

hladdr=`expr "$hladdr" : '\([0-9a-f][0-9a-f]*\).*'`

DOS

Powershell

$regex = [regex]"[0-9a-f][0-9a-f]*"
$hladdr=$regex.Matches($hladdr) | ForEach-Object {$($_.Value)}

echo输出

Bash

echo "download normal.out" >> mdb.cmd

DOS

echo download normal.out >> mdb.cmd

Powershell

echo download normal.out >> mdb.cmd
Comments
Write a Comment
'