Run a string as a command within a Bash script

前端 未结 8 905
清歌不尽
清歌不尽 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 10:04

    For me echo XYZ_20200824.zip | grep -Eo '[[:digit:]]{4}[[:digit:]]{2}[[:digit:]]{2}' was working fine but unable to store output of command into variable. I had same issue I tried eval but didn't got output.

    Here is answer for my problem: cmd=$(echo XYZ_20200824.zip | grep -Eo '[[:digit:]]{4}[[:digit:]]{2}[[:digit:]]{2}')

    echo $cmd

    My output is now 20200824

    0 讨论(0)
  • 2020-12-07 10:05

    I usually place commands in parentheses $(commandStr), if that doesn't help I find bash debug mode great, run the script as bash -x script

    0 讨论(0)
提交回复
热议问题