shell编程,把sh文件翻译成bat文件

haiwalt 2012-12-11 05:32:51
我想把这段代码在windows中运行


#!/bin/sh

# use $JDK_HOME or $NB_JDK_HOME or the -jdkhome switch, do not edit this here
# (see below for info on .runide_defaults.sh)
jdkhome=""

# append on command line or ide.cfg, with -J prefix on each
jreflags=""

PRG=$0

#
# resolve symlinks
#

while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done

progdir=`dirname "$PRG"`
progname=`basename "$0"`

idehome="$progdir/.."

# absolutize idehome

oldpwd=`pwd` ; cd "${idehome}"; idehome=`pwd`; cd "${oldpwd}"; unset oldpwd

# calculate branding to brand userdir with
defaults="$idehome/bin/.runide_defaults.sh"
if [ -r "$idehome/lib/branding" ]; then
branding=`cat "$idehome/lib/branding"`
if [ -r "$idehome/bin/.runide_defaults_$branding.sh" ]; then
defaults="$idehome/bin/.runide_defaults_$branding.sh"
fi
fi
# This script should set the var userdir at the least:
# (another likely option would be $jdkhome, see #18628)
. "$defaults"

jargs=${jreflags}
jargs="$jargs -Dnetbeans.home=\"$idehome\""
jargs="$jargs -Djava.security.policy=\"$idehome/bin/ide.policy\""

args=""

prefixcp=""
postfixcp=""

updater_class=org.netbeans.updater.UpdaterFrame
ide_class_option=

#
# defaults
#

# if JDK_HOME is set it overrides ${JAVA_PATH}

if [ ! -z "$JDK_HOME" -a -z "$jdkhome" ] ; then
jdkhome="$JDK_HOME"
fi

# if JAVA_PATH is set it is used if necessary

if [ ! -z "$JAVA_PATH" -a -z "$jdkhome" ] ; then
jdkhome="$JAVA_PATH"
fi

#
# parse arguments
#

parse_args() {
while [ $# -gt 0 ] ; do
# echo "Processing arg: '$1'"
case "$1" in
-h|-?|-help|--help) cat >&2 <<EOF
Usage: $0 {options} arguments

General options:
--help show this help
--jdkhome <path> path to Java(TM) 2 SDK, Standard Edition
-J<jvm_option> pass <jvm_option> to JVM

--cp:p <classpath> prepend <classpath> to classpath
--cp:a <classpath> append <classpath> to classpath

EOF
# go on and print IDE options as well
args="$args --help" ;;
-jdkhome|--jdkhome) shift; if [ $# -gt 0 ] ; then jdkhome=$1; fi;;
# this has to be here for purposes of updater.jar, but it should be
# better to handle this argument inside the java launcher part
-userdir|--userdir) shift; if [ $# -gt 0 ] ; then userdir=$1; fi;;
# For compatibility only:
-mainclass) shift; if [ $# -gt 0 ] ; then ide_class_option=-Dnetbeans.mainclass=$1; fi;;
-cp|-cp:a|--cp|--cp:a)
shift;
if [ $# -gt 0 ] ; then
if [ ! -z "$postfixcp" ] ; then postfixcp="$postfixcp:" ; fi
postfixcp=$postfixcp$1;
fi
;;

-cp:p|--cp:p)
shift;
if [ $# -gt 0 ] ; then
if [ ! -z "$prefixcp" ] ; then prefixcp="$prefixcp:" ; fi
prefixcp=$prefixcp$1;
fi
;;

-J*) jopt=`expr "X-$1" : 'X--J\(.*\)'`; jargs="$jargs \"$jopt\"";;
*) args="$args \"$1\"" ;;
esac
shift
done
} # parse_args()

# Process any ./ide.cfg or ~/ide.cfg.
# Note that there is no quoting scheme for these files.
if [ -r "${HOME}/ide.cfg" ]; then
parse_args `cat "${HOME}"/ide.cfg`
elif [ -r "${progdir}/ide.cfg" ]; then
parse_args `cat "${progdir}"/ide.cfg`
# else leave as is
fi

if [ -f /usr/j2se/opt/javahelp/lib/jhall.jar ]; then
# See http://www.netbeans.org/issues/show_bug.cgi?id=22455
jhjar="`echo ${idehome}/modules/autoload/ext/jh-*.jar`"
parse_args "-J-Xbootclasspath/p:${jhjar}"
fi

# Process arguments given on the command line.
parse_args "$@"

#
# check JDK
#

if [ -z "$jdkhome" ] ; then
echo "Cannot find JDK. Please set the JDK_HOME environment variable to point" >&2
echo "to your JDK installation directory, or use the --jdkhome switch" >&2
exit 2
fi

if [ ! -x "${jdkhome}/bin/java" ] ; then
echo "Cannot find JDK at ${jdkhome}. Please set the JDK_HOME" >&2
echo "environment variable to point to your JDK installation directory," >&2
echo "or use the --jdkhome switch" >&2
exit 2
fi

#
# check userdir
#

if [ ! -z "$userdir" ] ; then
args="--userdir \"${userdir}\" $args"
fi

#
# increase file descriptor's limit, on Solaris it's set to 64, too small for
# fastjavac
#

ulimit -n 1024

append_jars_to_cp() {
dir="$1"
for ex in jar zip ; do
if [ "`echo "${dir}"/*.$ex`" != "${dir}/*.$ex" ] ; then
for x in "${dir}"/*.$ex ; do
if [ ! -z "$cp" ] ; then cp="$cp:" ; fi
cp="$cp$x"
done
fi
done
}

build_cp() {
base="$1"
append_jars_to_cp "${base}/lib/ext"
append_jars_to_cp "${base}/lib/ext/locale"
}

do_run_updater() {
eval "\"$jdkhome/bin/java\"" -classpath "\"${updatercp}\"" $jargs "-Dnetbeans.user=\"$userdir\"" $updater_class
}

look_for_pre_runs() {
base="$1"
dir="${base}/update/download"
if [ -f "${dir}/install_later.xml" -a "`echo "${dir}"/*.nbm`" != "${dir}/*.nbm" ] ; then
run_updater=yes
fi
}

look_for_post_runs() {
base="$1"
dir="${base}/update/download"
if [ \! -f "${dir}/install_later.xml" -a "`echo "${dir}"/*.nbm`" != "${dir}/*.nbm" ] ; then
run_updater=yes
fi
}

#
# dump the OS env variables into a temp file
#

nbenvfile="/tmp/nbenv.$$"

# attempt to delete a leftover from crashed instance which happened to have the
# same PID

rm -f ${nbenvfile}

# if ${nbenvfile} already exists there is a possibility that it is a leftover
# after another instance of this script crashed and the owner of the file can
# be another user (PIDs are reused). In such a case keep appending 'X' to the
# filename until we find an unused name

while [ -f "$nbenvfile" ]
do
nbenvfile=${nbenvfile}X
done

# #30621: handle embedded newlines in values, if possible.
if [ -r /proc/self/environ ]
then
cat /proc/self/environ > "$nbenvfile"
nbenvnullsep=true
# XXX works, but spends extra 350msec on a Solaris box I saw; probably too obscure to be worth it:
#elif perl -e 'foreach (keys %ENV) {print "$_=$ENV{$_}\0"}' > "$nbenvfile" 2> /dev/null
#then
# nbenvnullsep=true
elif [ -x /usr/bin/env ] ; then
/usr/bin/env > "$nbenvfile"
nbenvnullsep=false
else
echo "" > "$nbenvfile"
nbenvnullsep=false
fi

# Note that Bash calls this even if you stop the command with Ctrl-C;
# Solaris' /bin/sh does not - but both call it on normal exit.
trap "rm -f '$nbenvfile'" EXIT

#
# main loop
#

# clear to prevent loop from ending
restart="yes"
first_time_starting="yes"

while [ "$restart" ] ; do

#
# build CLASSPATH
#

cp=""
updatercp=""

build_cp "${idehome}"

if [ -f "${idehome}/lib/updater.jar" ] ; then
updatercp="${idehome}/lib/updater.jar"
fi

# JDK tools

for ex in jar zip ; do
# XXX does this still work if ${jdkhome} contains spaces?
if [ "`echo "${jdkhome}"/lib/*.$ex`" != "${jdkhome}/lib/*.$ex" ] ;then
for x in "${jdkhome}"/lib/*.$ex ; do
if [ ! -z "$cp" ] ; then cp="$cp:" ; fi
cp="${cp}$x"
done
fi
done

# user-specified prefix and postfix CLASSPATH

if [ ! -z "${prefixcp}" ] ; then
cp="${prefixcp}:$cp"
fi

if [ ! -z "${postfixcp}" ] ; then
cp="$cp:${postfixcp}"
fi


# prepend IDE's classpath to updater's classpath
# (just xml-apis.jar and one XML parser would suffice)
if [ ! -z "$updatercp" ] ; then
updatercp=${cp}:${updatercp}
else
updatercp=${cp}
fi

# First check for pre-run updates.
if [ "$first_time_starting" ] ; then
run_updater=""
look_for_pre_runs "$idehome"
look_for_pre_runs "$userdir"
if [ "$run_updater" ] ; then do_run_updater ; fi
# Do not check this after a restart, it makes no sense.
first_time_starting=""
fi

#
# let's go
#

eval ${_NB_PROFILE_CMD} "\"${jdkhome}/bin/java\"" -Djdk.home="\"${jdkhome}\"" -classpath "\"$cp\"" \
-Dnetbeans.osenv="${nbenvfile}" -Dnetbeans.osenv.nullsep=${nbenvnullsep} \
$jargs $ide_class_option org.netbeans.Main $args
exitcode=$?

# If we should update anything, do it and restart IDE.
run_updater=""
look_for_post_runs "$idehome"
look_for_post_runs "$userdir"
if [ "$run_updater" ] ; then
do_run_updater
restart="yes"
else
restart=""
# will fall thru loop and exit
fi

done

# and we exit.
exit $exitcode



由于csdn没有提供shell的语法格式,这段代码我用perl显示出来的,可能要方便阅读一点。
各位大侠就来一显身手吧

...全文
867 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljc007 2012-12-24
  • 打赏
  • 举报
回复
引用 9 楼 wangwenwen 的回复:
这个脚本不会是哪个开源程序中自带的吧,去下个windows版本的、里面估计就自带了对应的.bat 。 几句话解决不了的问题一般在论坛上不会有结果的。
500RMB 这活我接了
fdl19881 2012-12-22
  • 打赏
  • 举报
回复
++ 因为一般此类几句话解决不了的问题,说明提问者本身对问的东西基本不懂。 那么要给提问者讲清楚这个问题,就得长篇大论了,所以大部分人看到这类问题都不会分析半天,然后再打N多字。
引用 9 楼 wangwenwen 的回复:
这个脚本不会是哪个开源程序中自带的吧,去下个windows版本的、里面估计就自带了对应的.bat 。 几句话解决不了的问题一般在论坛上不会有结果的。
wangwenwen 2012-12-21
  • 打赏
  • 举报
回复
这个脚本不会是哪个开源程序中自带的吧,去下个windows版本的、里面估计就自带了对应的.bat 。 几句话解决不了的问题一般在论坛上不会有结果的。
haiwalt 2012-12-13
  • 打赏
  • 举报
回复
顶一下,别掉了
haiwalt 2012-12-12
  • 打赏
  • 举报
回复
其实对shell熟悉的人,稍微分析下就知道这个是怎样的逻辑了, 但是我菜鸟一只,对其中一些代码一点都看不懂 如果无法翻译,把这段代码的逻辑详述一下,也算帮助我了
personball 2012-12-12
  • 打赏
  • 举报
回复
神需求 楼主提出的这个需求,得问微软要解决方案 要么楼主的windows上装个powershell 试试
haiwalt 2012-12-12
  • 打赏
  • 举报
回复
只有这个sh版本的,求解惑啊
haiwalt 2012-12-12
  • 打赏
  • 举报
回复
好嘛, 翻译下面一段就行了

append_jars_to_cp() {
    dir="$1"
    for ex in jar zip ; do
        if [ "`echo "${dir}"/*.$ex`" != "${dir}/*.$ex" ] ; then
            for x in "${dir}"/*.$ex ; do
                if [ ! -z "$cp" ] ; then cp="$cp:" ; fi
                cp="$cp$x"
            done
        fi
    done
}
ForestDB 2012-12-11
  • 打赏
  • 举报
回复
netbeans的启动脚本? 直接就有bat版的吧。
haiwalt 2012-12-11
  • 打赏
  • 举报
回复
必须要改啊,这段代码要配置程序在windows中运行的环境
沭水河畔 2012-12-11
  • 打赏
  • 举报
回复
不好改,不如改用Cygwin来运行。
内容概要:本文围绕“评估多目标跟踪方法”,通过Matlab代码实现,系统研究了9个高度敏捷目标在密集编队飞行中的轨迹生与测量数据模拟。研究构建了一个高保真的仿真环境,用于测试和验证多目标跟踪算法的性能,重点模拟了目标的高机动性运动行为以及受噪声影响的观测过程,涵盖了轨迹建模、传感器测量仿真、噪声注入与数据处理等关键技术环节。该仿真平台可为雷达系统、无人机集群监控、空中交通管制等领域中的跟踪算法研发提供标准化、可复现的实验基础,尤其适用于评估JPDA、IMM-PF、PHD滤波等先进跟踪算法在复杂动态环境下的鲁棒性与准确性。研究果具备较强的工程应用价值和学术研究意义。; 适合人群:具备一定Matlab编程基础,从事雷达信号处理、多目标跟踪、智能监控、无人机编队控制、自动化与信息工程等方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①为多目标跟踪算法(如JPDA、IMM、PHD滤波等)提供标准的高机动目标仿真测试环境;②研究密集编队下高机动目标的轨迹可观测性、测量模糊性与数据关联挑战;③支持学术论文中实验部分的复现、对比分析与算法性能验证。; 阅读建议:建议结合文中提供的Matlab代码深入理解轨迹动力学建模与观测模型的设计逻辑,可通过调整目标机动参数、传感器噪声水平、遮挡概率或引入多传感器融合机制,进一步拓展仿真场景,以全面评估跟踪算法在不同复杂条件下的适应性与鲁棒性。

19,614

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧