2 years ago

#66372

test-img

Lucian Thorr

eval or sed is inserting single-quotes

I'm trying to automate a command that takes a list of files as arguments and running into an issue where either sed or the $() evaluation is inserting single-quotes into the returned response.

The total script is as follows:

#!/bin/sh
./update $(ls $PWD | sed "s#\(.*\)#$PWD\/\1#g" | sed 's# #\\ #g')

Essentially, run update where it receives a list of files as arguments. the first sed adds the absolute path to the files and the second sed replaces spaces with backslash-escaped spaces.

If I run the ls $PWD | sed "s#\(.*\)#$PWD\/\1#g" | sed -e 's# #\\ #g' on the command-line, it works as expected but when run inside the $() evaluation it wraps every line that received the backslash-escaped replacement with single quotes.

so instead of running:

update file\ A.txt file\ B.txt fileC.txt

it runs:

update 'file\' A.txt 'file\' B.txt fileC.txt

What can I do to remove those single-quotes? I've tried piping the output to another sed to remove single-quotes but it seems like the matches just put them back.

bash

shell

sed

sh

eval

0 Answers

Your Answer

Accepted video resources