我有批处理文件,我不知道shell脚本。 有人可以帮忙吗?
@echo off
echo "Program Name :" %0
rem echo "Next param :" %1
echo "Next param :" "Username/Password"
echo "User Id :" %2
echo "User Name :" %3
echo "Request ID :" %4
echo "File Name :" %5
echo "Entity Name :" %6
echo "Email Address :" %7
echo "Extract ID :" %8
echo "path name :" %9
cd %9
echo "Process Output files"
IF NOT EXIST C:\OraOutput GOTO MAPERROR
IF EXIST o%8.out (COPY o%8.out %5.csv) ELSE echo "Output file does not exists"
IF EXIST %5.csv (MOVE %5.csv C:\OraOutput\%5.cvs) ELSE echo "Could not move file to Share Drive"
GOTO ENDPROCESS
:MAPERROR
echo "The Share Directory has not been mapped Contact your System Administrator"
EXIT -1
:ENDPROCESS
echo "Process finished goodbye"
感谢。
答案 0 :(得分:0)
我假设更多或更少与Bourne兼容的shell,如bash
,因为这是最常见的。首先,为了将批处理脚本转换为Bourne样式shell脚本,您需要了解一些差异:
#
开头。cd
和echo
以及exit
也存在于Bourne兼容的shell中。[ -e
文件名 ]
。IF
语句变为if
条件 ; then
true-statement ; else
false-statement < / em> ; fi
您可以在其中使用分号代替 true-statement 和 false-statement 分隔多个命令/语句。 IF EXIST o%8.out (COPY o%8.out %5.csv) ELSE echo "Output file does not exists"
看起来像
# I am assuming %8 means parameter 8 for the script
if [ -e o$8.out ]; then cp o$8.out $5.csv; else echo "Output file does not exist"; fi
或使用替代缩进(分号可以替换为新行):
if [ -e o$8.out ]; then
cp "o$8.out" "$5.csv"
else
echo "Output file does not exist"
fi
请注意,我们还引用了cp
的参数,以便我们可以在参数中使用空格。
goto
。您可以参考此Stack Overflow问题(假设bash
或其他Bourne shell样式脚本方言):Is there a "goto" statement in bash?