명령으로 실행할 문자열을 빌드하는 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
답변
일반적으로 괄호 안에 명령을 넣습니다 $(commandStr)
. bash 디버그 모드를 찾는 데 도움이되지 않으면 스크립트를 다음과 같이 실행하십시오.bash -x script
답변
your_command_string="..."
output=$(eval "$your_command_string")
echo "$output"
답변
명령을 변수에 넣지 말고 실행하십시오.
matchdir="/home/joao/robocup/runner_workdir/matches/testmatch/"
PWD=$(pwd)
teamAComm="$PWD/a.sh"
teamBComm="$PWD/b.sh"
include="$PWD/server_official.conf"
serverbin='/usr/local/bin/rcssserver'
cd $matchdir
$serverbin include=$include server::team_l_start = ${teamAComm} server::team_r_start=${teamBComm} CSVSaver::save='true' CSVSaver::filename = 'out.csv'
답변
./me 캐스트 raise_dead ()
나는 이와 같은 것을 찾고 있었지만 동일한 문자열에서 두 개의 매개 변수를 뺀 매개 변수를 다시 사용해야하므로 다음과 같은 결과가 나왔습니다.
my_exe ()
{
mysql -sN -e "select $1 from heat.stack where heat.stack.name=\"$2\";"
}
이것은 오픈 스택 열 스택 생성을 모니터링하는 데 사용하는 것입니다. 이 경우 “CREATE”조치와 “Somestack”이라는 스택에서 상태 ‘COMPLETE’의 두 가지 조건이 예상됩니다.
이러한 변수를 얻으려면 다음과 같이 할 수 있습니다.
ACTION=$(my_exe action Somestack)
STATUS=$(my_exe status Somestack)
if [[ "$ACTION" == "CREATE" ]] && [[ "$STATUS" == "COMPLETE" ]]
...
답변
heredocs에 저장된 문자열을 실행하는 gradle 빌드 스크립트는 다음과 같습니다 .
current_directory=$( realpath "." )
GENERATED=${current_directory}/"GENERATED"
build_gradle=$( realpath build.gradle )
## touch because .gitignore ignores this folder:
touch $GENERATED
COPY_BUILD_FILE=$( cat <<COPY_BUILD_FILE_HEREDOC
cp
$build_gradle
$GENERATED/build.gradle
COPY_BUILD_FILE_HEREDOC
)
$COPY_BUILD_FILE
GRADLE_COMMAND=$( cat <<GRADLE_COMMAND_HEREDOC
gradle run
--build-file
$GENERATED/build.gradle
--gradle-user-home
$GENERATED
--no-daemon
GRADLE_COMMAND_HEREDOC
)
$GRADLE_COMMAND
고독한 “)”는 못 생겼습니다. 그러나 나는 그 천식을 고치는 방법에 대한 단서가 없다.
답변
스크립트에 의해 실행되는 모든 명령을 보려면 -x
shabang 행에 플래그를 추가 하고 명령을 정상적으로 실행하십시오.
#! /bin/bash -x
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
$serverbin include="$include" server::team_l_start="${teamAComm}" server::team_r_start="${teamBComm}" CSVSaver::save='true' CSVSaver::filename='out.csv'
그런 다음 가끔 디버그 출력을 무시하려면 stderr
어딘가로 리디렉션하십시오 .