Run a string as a command within a Bash script

前端 未结 8 963
清歌不尽
清歌不尽 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条回答
  •  旧时难觅i
    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

提交回复
热议问题