加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在Bash脚本中作为命令运行字符串

发布时间:2020-12-15 16:40:16 所属栏目:安全 来源:网络整理
导读:我有一个Bash脚本,构建一个字符串作为命令运行 脚本: #! /bin/bashmatchdir="/home/joao/robocup/runner_workdir/matches/testmatch/"teamAComm="`pwd`/a.sh"teamBComm="`pwd`/b.sh"include="`pwd`/server_official.conf"serverbin='/usr/local/bin/rcssse
我有一个Bash脚本,构建一个字符串作为命令运行

脚本:

#! /bin/bash

matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/"

teamAComm="`pwd`/a.sh"
teamBComm="`pwd`/b.sh"
include="`pwd`/server_official.conf"
serverbin='/usr/local/bin/rcssserver'

cd $matchdir
illcommando="$serverbin include='$include' server::team_l_start = '${teamAComm}' server::team_r_start = '${teamBComm}' CSVSaver::save='true' CSVSaver::filename = 'out.csv'"

echo "running: $illcommando"
# $illcommando > server-output.log 2> server-error.log
$illcommando

这似乎不正确地提供参数到$ serverbin。

脚本输出:

running: /usr/local/bin/rcssserver include='/home/joao/robocup/runner_workdir/server_official.conf' server::team_l_start = '/home/joao/robocup/runner_workdir/a.sh' server::team_r_start = '/home/joao/robocup/runner_workdir/b.sh' CSVSaver::save='true' CSVSaver::filename = 'out.csv'
rcssserver-14.0.1

Copyright (C) 1995,1996,1997,1998,1999 Electrotechnical Laboratory.
2000 - 2009 RoboCup Soccer Simulator Maintenance Group.


Usage: /usr/local/bin/rcssserver [[-[-]]namespace::option=value]
                                 [[-[-]][namespace::]help]
                                 [[-[-]]include=file]
Options:
    help
        display generic help

    include=file
        parse the specified configuration file.  Configuration files
        have the same format as the command line options. The
        configuration file specified will be parsed before all
        subsequent options.

    server::help
        display detailed help for the "server" module

    player::help
        display detailed help for the "player" module

    CSVSaver::help
        display detailed help for the "CSVSaver" module

CSVSaver Options:
    CSVSaver::save=<on|off|true|false|1|0|>
        If save is on/true,then the saver will attempt to save the
        results to the database.  Otherwise it will do nothing.

        current value: false

    CSVSaver::filename='<STRING>'
        The file to save the results to.  If this file does not
        exist it will be created.  If the file does exist,the results
        will be appended to the end.

        current value: 'out.csv'

如果我只是粘贴命令/usr/local/bin / rcssserver include =’/ home / joao / robocup / runner_workdir / server_official.conf’server :: team_l_start =’/home/joao/robocup/runner_workdir/a.sh’server :: team_r_start =’/home/joao/robocup/runner_workdir/b.sh’CSVSaver :: save =’true’CSVSaver :: filename =’out.csv'(在“runnning:”之后的输出中)它工作正常。

您可以使用eval执行字符串:
eval $illcommando

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读