bat文件和sh文件

tomcat的bin文件夹中存在一份.bat文件和相对应的.sh文件,一个是为了在window系统上执行的文件,另一个是linux下的批处理文件。例如:startup.bat和startup.sh。
bat是dos下的批处理文件批处理文件是无格式的文本文件,它包含一条或多条命令。它的文件扩展名为 .bat 或 .cmd。在命令提示下键入批处理文件的名称,或者双击该批处理文件,系统就会调用Cmd.exe按照该文件中各个命令出现的顺序来逐个运行它们。使用批处理文件(也被称为批处理程序脚本),可以简化日常或重复性任务。

一个中等水平的Linux用户一定少不了经常执行.sh文件,当然了,你可以在图形界面下面直接双击该文件,但无疑比较浪费时间。

现在介绍第一种方法:(在ubuntu下的)

首先你要打开一个终端。
然后输入sudo su
随后输入密码。这样就取得了root用户权限。
然后找到那个文件(当然是在终端里面用命令找,你可别开一个文件管理器。)
执行./sh文件名字
就可以了。

 

比如你有一个sh文件叫1.sh,这个文件在硬盘的/tmp目录里面,要执行的话,就要这样:

C代码  
  1. $ sudo su  
  2. pass your password:(这里输入密码的时候是看不到输入的东西的,不过确实已经输入进去了。)  
  3. #cd /tmp  
  4. #./1.sh  

 这样就OK了。

SH文件是Linux系统里面的类似批处理的文件,所以运行sh文件后可能会还要你输入一些信息。这个就视sh文件的内容而定了。

 

第二种方法:

sh xx.sh

 

最后建议:使用

C代码  
  1. man sh   

 来看看sh 的介绍~

阅读更多
换一批

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

12-11

我想把这段代码在windows中运行rnrn[code=perl]rn#!/bin/shrnrn# use $JDK_HOME or $NB_JDK_HOME or the -jdkhome switch, do not edit this herern# (see below for info on .runide_defaults.sh)rnjdkhome=""rnrn# append on command line or ide.cfg, with -J prefix on eachrnjreflags=""rnrnPRG=$0rnrn#rn# resolve symlinksrn#rnrnwhile [ -h "$PRG" ]; dorn ls=`ls -ld "$PRG"`rn link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`rn if expr "$link" : '^/' 2> /dev/null >/dev/null; thenrn PRG="$link"rn elsern PRG="`dirname "$PRG"`/$link"rn firndonernrnprogdir=`dirname "$PRG"`rnprogname=`basename "$0"`rnrnidehome="$progdir/.."rnrn# absolutize idehomernrnoldpwd=`pwd` ; cd "$idehome"; idehome=`pwd`; cd "$oldpwd"; unset oldpwdrnrn# calculate branding to brand userdir withrndefaults="$idehome/bin/.runide_defaults.sh"rnif [ -r "$idehome/lib/branding" ]; thenrn branding=`cat "$idehome/lib/branding"`rn if [ -r "$idehome/bin/.runide_defaults_$branding.sh" ]; thenrn defaults="$idehome/bin/.runide_defaults_$branding.sh"rn firnfirn# This script should set the var userdir at the least:rn# (another likely option would be $jdkhome, see #18628)rn. "$defaults"rnrnjargs=$jreflagsrnjargs="$jargs -Dnetbeans.home=\"$idehome\""rnjargs="$jargs -Djava.security.policy=\"$idehome/bin/ide.policy\""rnrnargs=""rnrnprefixcp=""rnpostfixcp=""rnrnupdater_class=org.netbeans.updater.UpdaterFramernide_class_option=rnrn#rn# defaultsrn#rnrn# if JDK_HOME is set it overrides $JAVA_PATHrnrnif [ ! -z "$JDK_HOME" -a -z "$jdkhome" ] ; thenrn jdkhome="$JDK_HOME"rnfirnrn# if JAVA_PATH is set it is used if necessaryrnrnif [ ! -z "$JAVA_PATH" -a -z "$jdkhome" ] ; thenrn jdkhome="$JAVA_PATH"rnfirnrn#rn# parse argumentsrn#rnrnparse_args() rnwhile [ $# -gt 0 ] ; dorn# echo "Processing arg: '$1'"rn case "$1" inrn -h|-?|-help|--help) cat >&2 < path to Java(TM) 2 SDK, Standard Editionrn -J pass to JVMrnrn --cp:p prepend to classpathrn --cp:a append to classpathrnrnEOFrn # go on and print IDE options as wellrn args="$args --help" ;;rn -jdkhome|--jdkhome) shift; if [ $# -gt 0 ] ; then jdkhome=$1; fi;;rn # this has to be here for purposes of updater.jar, but it should bern # better to handle this argument inside the java launcher part rn -userdir|--userdir) shift; if [ $# -gt 0 ] ; then userdir=$1; fi;;rn # For compatibility only:rn -mainclass) shift; if [ $# -gt 0 ] ; then ide_class_option=-Dnetbeans.mainclass=$1; fi;;rn -cp|-cp:a|--cp|--cp:a)rn shift;rn if [ $# -gt 0 ] ; thenrn if [ ! -z "$postfixcp" ] ; then postfixcp="$postfixcp:" ; firn postfixcp=$postfixcp$1;rn firn ;;rn rn -cp:p|--cp:p)rn shift;rn if [ $# -gt 0 ] ; thenrn if [ ! -z "$prefixcp" ] ; then prefixcp="$prefixcp:" ; firn prefixcp=$prefixcp$1;rn firn ;;rn rn -J*) jopt=`expr "X-$1" : 'X--J\(.*\)'`; jargs="$jargs \"$jopt\"";;rn *) args="$args \"$1\"" ;;rn esacrn shiftrndonern # parse_args()rnrn# Process any ./ide.cfg or ~/ide.cfg.rn# Note that there is no quoting scheme for these files.rnif [ -r "$HOME/ide.cfg" ]; thenrn parse_args `cat "$HOME"/ide.cfg`rnelif [ -r "$progdir/ide.cfg" ]; thenrn parse_args `cat "$progdir"/ide.cfg`rn# else leave as isrnfirnrnif [ -f /usr/j2se/opt/javahelp/lib/jhall.jar ]; thenrn # See http://www.netbeans.org/issues/show_bug.cgi?id=22455rn jhjar="`echo $idehome/modules/autoload/ext/jh-*.jar`"rn parse_args "-J-Xbootclasspath/p:$jhjar"rnfirnrn# Process arguments given on the command line.rnparse_args "$@"rnrn#rn# check JDKrn#rnrnif [ -z "$jdkhome" ] ; thenrn echo "Cannot find JDK. Please set the JDK_HOME environment variable to point" >&2rn echo "to your JDK installation directory, or use the --jdkhome switch" >&2rn exit 2rnfirnrnif [ ! -x "$jdkhome/bin/java" ] ; thenrn echo "Cannot find JDK at $jdkhome. Please set the JDK_HOME" >&2rn echo "environment variable to point to your JDK installation directory," >&2rn echo "or use the --jdkhome switch" >&2rn exit 2rnfirnrn#rn# check userdirrn#rnrnif [ ! -z "$userdir" ] ; thenrn args="--userdir \"$userdir\" $args"rnfirnrn#rn# increase file descriptor's limit, on Solaris it's set to 64, too small forrn# fastjavacrn#rnrnulimit -n 1024rnrnappend_jars_to_cp() rn dir="$1"rn for ex in jar zip ; dorn if [ "`echo "$dir"/*.$ex`" != "$dir/*.$ex" ] ; thenrn for x in "$dir"/*.$ex ; dorn if [ ! -z "$cp" ] ; then cp="$cp:" ; firn cp="$cp$x"rn donern firn donernrnrnbuild_cp() rn base="$1"rn append_jars_to_cp "$base/lib/ext"rn append_jars_to_cp "$base/lib/ext/locale"rnrnrndo_run_updater() rn eval "\"$jdkhome/bin/java\"" -classpath "\"$updatercp\"" $jargs "-Dnetbeans.user=\"$userdir\"" $updater_classrnrnrnlook_for_pre_runs() rn base="$1"rn dir="$base/update/download"rn if [ -f "$dir/install_later.xml" -a "`echo "$dir"/*.nbm`" != "$dir/*.nbm" ] ; thenrn run_updater=yesrn firnrnrnlook_for_post_runs() rn base="$1"rn dir="$base/update/download"rn if [ \! -f "$dir/install_later.xml" -a "`echo "$dir"/*.nbm`" != "$dir/*.nbm" ] ; thenrn run_updater=yesrn firnrnrn#rn# dump the OS env variables into a temp filern#rnrnnbenvfile="/tmp/nbenv.$$"rnrn# attempt to delete a leftover from crashed instance which happened to have thern# same PIDrnrnrm -f $nbenvfilernrn# if $nbenvfile already exists there is a possibility that it is a leftoverrn# after another instance of this script crashed and the owner of the file canrn# be another user (PIDs are reused). In such a case keep appending 'X' to thern# filename until we find an unused namernrnwhile [ -f "$nbenvfile" ]rndorn nbenvfile=$nbenvfileXrndonernrn# #30621: handle embedded newlines in values, if possible.rnif [ -r /proc/self/environ ]rnthenrn cat /proc/self/environ > "$nbenvfile"rn nbenvnullsep=truern# XXX works, but spends extra 350msec on a Solaris box I saw; probably too obscure to be worth it:rn#elif perl -e 'foreach (keys %ENV) print "$_=$ENV$_\0"' > "$nbenvfile" 2> /dev/nullrn#thenrn# nbenvnullsep=truernelif [ -x /usr/bin/env ] ; thenrn /usr/bin/env > "$nbenvfile"rn nbenvnullsep=falsernelsern echo "" > "$nbenvfile"rn nbenvnullsep=falsernfirnrn# Note that Bash calls this even if you stop the command with Ctrl-C;rn# Solaris' /bin/sh does not - but both call it on normal exit.rntrap "rm -f '$nbenvfile'" EXITrnrn#rn# main looprn#rnrn# clear to prevent loop from endingrnrestart="yes"rnfirst_time_starting="yes"rnrnwhile [ "$restart" ] ; dornrn #rn # build CLASSPATHrn #rn rn cp=""rn updatercp=""rn rn build_cp "$idehome"rn rn if [ -f "$idehome/lib/updater.jar" ] ; thenrn updatercp="$idehome/lib/updater.jar"rn firnrn # JDK toolsrn rn for ex in jar zip ; dorn # XXX does this still work if $jdkhome contains spaces?rn if [ "`echo "$jdkhome"/lib/*.$ex`" != "$jdkhome/lib/*.$ex" ] ;thenrn for x in "$jdkhome"/lib/*.$ex ; dorn if [ ! -z "$cp" ] ; then cp="$cp:" ; firn cp="$cp$x"rn donern firn donernrn # user-specified prefix and postfix CLASSPATHrn rn if [ ! -z "$prefixcp" ] ; thenrn cp="$prefixcp:$cp"rn firn rn if [ ! -z "$postfixcp" ] ; thenrn cp="$cp:$postfixcp"rn firnrnrn # prepend IDE's classpath to updater's classpathrn # (just xml-apis.jar and one XML parser would suffice)rn if [ ! -z "$updatercp" ] ; thenrn updatercp=$cp:$updatercprn elsern updatercp=$cprn firnrn # First check for pre-run updates.rn if [ "$first_time_starting" ] ; thenrn run_updater=""rn look_for_pre_runs "$idehome"rn look_for_pre_runs "$userdir"rn if [ "$run_updater" ] ; then do_run_updater ; firn # Do not check this after a restart, it makes no sense.rn first_time_starting=""rn firn rn #rn # let's gorn #rnrn eval $_NB_PROFILE_CMD "\"$jdkhome/bin/java\"" -Djdk.home="\"$jdkhome\"" -classpath "\"$cp\"" \rn -Dnetbeans.osenv="$nbenvfile" -Dnetbeans.osenv.nullsep=$nbenvnullsep \rn $jargs $ide_class_option org.netbeans.Main $argsrn exitcode=$?rnrn # If we should update anything, do it and restart IDE.rn run_updater=""rn look_for_post_runs "$idehome"rn look_for_post_runs "$userdir"rn if [ "$run_updater" ] ; thenrn do_run_updaterrn restart="yes"rn elsern restart=""rn # will fall thru loop and exitrn firnrndonernrn# and we exit.rnexit $exitcodernrn[/code]rnrn由于csdn没有提供shell的语法格式,这段代码我用perl显示出来的,可能要方便阅读一点。rn各位大侠就来一显身手吧rnrn

没有更多推荐了,返回首页