shell - How to remove quotes around each element in bash array created from grep capture -
in bash function, using grep capture matching pattern string (selecting files created), , storing captured in array. string assigned variable called output
installing route create app/routes/foo.js create app/templates/foo.hbs updating router add route foo installing route-test create tests/unit/routes/foo-test.js
after running
files=($(echo "$output" | ggrep -op 'create\s\k(.+)'))
i confirm capturing intend running echo ${files[*]}
. output in terminal looks so
app/routes/foo.js app/templates/foo.hbs tests/unit/routes/foo-test.js
my goal pass these files arguments npm script (npm run lint <list of files>
). however, when try plug in variable npm script execution, file names either print out like
"app/routes/foo.js" "app/templates/foo.hbs" "tests/unit/routes/foo-test.js"
or
"app/routes/foo.js app/templates/foo.hbs tests/unit/routes/foo-test.js"
the ultimate goal here able run
npm run lint app/routes/foo.js app/templates/foo.hbs tests/unit/routes/foo-test.js
i have tried tons of combinations interpolate file
variable, nothing seems work. feel missing conceptually or approaching in wrong way. trying without using array file
, running same issue. first pass getting run in bash. however, i'd prefer stick using grep
or sed
here though. have suggestions?
after reading suggestions have tried
parsedfiles=$(echo "${files[*]}" | sed -e 's/"//g') echo $parsedfiles npm run lint $parsedfiles
when echo $parsedfiles
runs terminal output looks app/routes/foo.js app/templates/foo.hbs tests/unit/routes/foo-test.js
, on next line, still outputs npm run "app/routes/foo.js" "app/templates/foo.hbs" "tests/unit/routes/foo-test.js"
solved real issue here wasn't how passing args in. it's issue running npm script
. when passing args npm script automatically puts them in double quotes.
use sed edit text below.
$ var=`echo "app/routes/foo.js app/templates/foo.hbs tests/unit/routes/foo-test.js" | sed -e 's/"//g'` test$ echo $var app/routes/foo.js app/templates/foo.hbs tests/unit/routes/foo-test.js
now can use var in npm run lint
$ npm run lint $var
Comments
Post a Comment