Run a string as a command within a Bash script

前端 未结 8 932
清歌不尽
清歌不尽 2020-12-07 09:08

I have a Bash script that builds a string to run as a command

Script:

#! /bin/bash

matchdir=\"/home/joao/robocup/runner_workdir/mat         


        
8条回答
  •  再見小時候
    2020-12-07 09:43

    ./me casts raise_dead()

    I was looking for something like this, but I also needed to reuse the same string minus two parameters so I ended up with something like:

    my_exe ()
    {
        mysql -sN -e "select $1 from heat.stack where heat.stack.name=\"$2\";"
    }
    

    This is something I use to monitor openstack heat stack creation. In this case I expect two conditions, an action 'CREATE' and a status 'COMPLETE' on a stack named "Somestack"

    To get those variables I can do something like:

    ACTION=$(my_exe action Somestack)
    STATUS=$(my_exe status Somestack)
    if [[ "$ACTION" == "CREATE" ]] && [[ "$STATUS" == "COMPLETE" ]]
    ...
    

提交回复
热议问题