bat 如何传参数给 shell

我这边windows环境下有个小工具,内含psftp和putty,可以完成拷贝tar包到linux环境下执行包,然后将执行的结果拷回windows环境下。但是现在执行包需要输入参数,不清楚如何在环境间传递参数。请各位高手给出回答,有思路也行,能贴代码更好了。

#include <stdio.h>
#include <stdlib.h>
main()
{
system("123.bat haha");
}

.bat里:
echo %1

执行后输出
haha

所以在system要执行的脚本名后面直接加上参数就可以了
#!/bin/sh

if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 [config_file]
exit 127
fi

SOURCE=`awk -F"=" '/^database_name/ { print $2 }' $1`
SECONDS=`date +%s`
TARGET=$SOURCE"_"$SECONDS
DESTINATION=../$SOURCE.$DIALOG.$VERSION

echo Database: $SOURCE
echo Dialog ID: $DIALOG

#drop the target databse
psql -c "drop database $TARGET"

#create database objects
psql $TARGET < postgres_create.sql

#copy base tables
psql -c "copy (select * from message) to stdout" $SOURCE | psql -c "copy message from stdin" $TARGET

$TARGET
psql -c "copy (select * from qs_publicationstatustype) to stdout" $SOURCE | psql -c "copy qs_publicationstatustype from

stdin" $TARGET

#save the dialog
psql -c "copy (select * from q_dialog where q_dialog_id = $DIALOG) to stdout" $SOURCE | psql -c "copy q_dialog from stdin"

$TARGET

#create database objects
psql $TARGET < postgres_index.sql

#make the destination directory
mkdir -p $DESTINATION
mkdir -p $DESTINATION/cdd
mkdir -p $DESTINATION/corticon

#create readme files
echo "Note: Rules assets are owned by a different user and will have to be copied separately" >> $DESTINATION/cdd/README
echo "Note: Rules assets are owned by a different user and will have to be copied separately" >>

$DESTINATION/corticon/README

#export the database
pg_dump $TARGET > $DESTINATION/postgres_create.sql

#copy the import template to the destination
cp $TEMPLATE $DESTINATION/dialogsImport.sh
chmod +x $DESTINATION/dialogsImport.sh

#drop the temp database
psql -c "drop database $TARGET"

#append to the import config file
echo "database_name=$SOURCE" >> $DESTINATION/import.cfg

#append to the import README file

echo "*********************************************" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "* Program: dialogsImport" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "* Version 0.5" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "* Author: Dan Dreon" >> $DESTINATION/README
echo "*" >> $DESTINATION/README
echo "*********************************************" >> $DESTINATION/README

echo "* run this script as the database user - typically postgres" >> $DESTINATION/README
echo "* run this script from inside the dialogsImport folder" >> $DESTINATION/README
echo "* psql must be in your path" >> $DESTINATION/README
echo "* first edit the import.cfg script and enter the appropriate values" >> $DESTINATION/README
echo "* to run this script type ./dialogsImport import.cfg" >> $DESTINATION/README
echo "* Note: rules assets need to be copied separately" >> $DESTINATION/README

#archive the directory
tar -zcvf $DESTINATION.tar.gz $DESTINATION

#delete the original
rm -rf $DESTINATION

如何把这个shell脚本移植到windows 的bat中?各位大虾们,小弟现在有个棘手的问题,请大虾们给以帮助。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-07-08
是的,直接在命令提示符下键入你的bat命令,用空格分隔参数,然后在bat中用%1就是第一个参数的内容,%2就是第二个参数的内容。追问

不是问怎么调用参数执行bat,而是如何用将bat的参数传递到shell中啊。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网