我有一个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:“)它工作得很好。
8条答案
按热度按时间krcsximq1#
你可以使用
eval
来执行一个字符串:如果您的命令字符串需要在运行之前对其本身进行评估-请用引号括起来:
1yjd4xko2#
hmae6n7t3#
我通常将命令放在括号中
$(commandStr)
,如果这不能帮助我找到bash调试模式,那么以bash -x script
运行脚本vnzz0bqm4#
不要把你的命令放在变量中,只要运行它
mutmk8jj5#
./me转换raise_dead()
我正在寻找这样的东西,但我还需要重用相同的字符串减去两个参数,所以我最终得到了这样的东西:
这是我用来监视openstack热栈创建的东西。在这种情况下,我期望两个条件,一个动作'CREATE'和一个名为“Somestack”的堆栈上的状态'COMPUTER'。
为了得到这些变量,我可以这样做:
nwlls2ji6#
下面是我的gradle构建脚本,它执行存储在heredocs中的字符串:
唯一的“)”有点丑。但我不知道如何解决这个审美方面。
wswtfjt77#
要查看脚本正在执行的所有命令,请将
-x
标志添加到shabang行,然后正常执行命令:然后,如果您有时想忽略调试输出,请将
stderr
重定向到某个位置。sulc1iza8#
对我来说,
echo XYZ_20200824.zip | grep -Eo '[[:digit:]]{4}[[:digit:]]{2}[[:digit:]]{2}'
工作正常,但无法将命令的输出存储到变量中。我有同样的问题,我尝试eval
,但没有得到输出。以下是我的问题的答案:
cmd=$(echo XYZ_20200824.zip | grep -Eo '[[:digit:]]{4}[[:digit:]]{2}[[:digit:]]{2}')
echo $cmd
现在的输出是
20200824