Bash: Word splitting result of command substitution recognizing returned quotesWhy is looping over find's...

How to compare two different formulations of a problem?

To "hit home" in German

The economy of trapping

How to analyze "dearly beloved"?

Do I have to learn /o/ or /ɔ/ separately?

How much code would a codegolf golf if a codegolf could golf code?

Can pay be witheld for hours cleaning up after closing time?

Why we don't have vaccination against all diseases which are caused by microbes?

Something in the TV

Vacuum collapse -- why do strong metals implode but glass doesn't?

Why didn’t Doctor Strange stay in the original winning timeline?

How to look up identical column names in two dataframes and combine the matched columns

Are thrust levers synchronized by default when pushed/pulled?

Efficiently pathfinding many flocking enemies around obstacles

Is it safe to remove the bottom chords of a series of garage roof trusses?

How to create a summation symbol with a vertical bar?

Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")

Dark side of an exoplanet - if it was earth-like would its surface light be detectable?

Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?

How to dismiss intrusive questions from a colleague with whom I don't work?

Overwrite file only if data

Why don't politicians push for fossil fuel reduction by pointing out their scarcity?

Does Git delete empty folders?

Church Booleans



Bash: Word splitting result of command substitution recognizing returned quotes


Why is looping over find's output bad practice?Word-splitting when parameter is used within command substitutionBash - Command substitution adds single quotesWhy don't word splitting and filename expansion apply to the conditional expression within `[[ … ]]`?Escaping double quotes for variables in bash and qmakeadding filepath in the filesPipelined Sed does not work on found filename inside Bash command substitution when invoked from Find “-exec”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







-1















What I ultimately want is to iterate over a set of filenames using find and loop on that list. (Yes, I know I can use -exec in find, but I have reasons why this doesn't work for me.)



for file in $(find . -type f -print | sed -e 's/^\(.*\)$/\"\1\"/') ; do echo $file ; done


This does not work when the file names have spaces in them. The script above attempts to solve this problem by returning double-quotes around each filename. But apparently bash considers the double-quotes just part of the adjacent characters. When a file name is a b c, echo is run on "a, b, and c" rather than abc.



Is there way to get bash to word-split recognizing the double-quotes as special characters?










share|improve this question

























  • Could you mention something about the reasons you allude to at the end of the first sentence? For the quotes to be recognised as quoting characters, the shell has to evaluate them. You do this with eval, for example. Otherwise, they are like any other characters without any special meaning. Using eval here would probably be more difficult to get right than actually using find with -exec. See e.g. Understanding the -exec option of `find`. Also, writing code that inserts quotes around text for the shell to use is almost always the wrong approach.

    – Kusalananda
    2 days ago













  • See BashFAQ #20: How can I find and safely handle file names containing newlines, spaces or both?

    – Gordon Davisson
    2 days ago











  • I have variables that span the processing of the filenames.

    – Steve Brandli
    2 days ago






  • 1





    If you really must loop over the output of find, then better to use a null-delimited while read loop as discussed here: Why is looping over find's output bad practice?

    – steeldriver
    2 days ago






  • 2





    You should update your question with your real-life issue. The issue that you have presented is easily solved with find ... -exec, or even just find ... -print.

    – Kusalananda
    2 days ago


















-1















What I ultimately want is to iterate over a set of filenames using find and loop on that list. (Yes, I know I can use -exec in find, but I have reasons why this doesn't work for me.)



for file in $(find . -type f -print | sed -e 's/^\(.*\)$/\"\1\"/') ; do echo $file ; done


This does not work when the file names have spaces in them. The script above attempts to solve this problem by returning double-quotes around each filename. But apparently bash considers the double-quotes just part of the adjacent characters. When a file name is a b c, echo is run on "a, b, and c" rather than abc.



Is there way to get bash to word-split recognizing the double-quotes as special characters?










share|improve this question

























  • Could you mention something about the reasons you allude to at the end of the first sentence? For the quotes to be recognised as quoting characters, the shell has to evaluate them. You do this with eval, for example. Otherwise, they are like any other characters without any special meaning. Using eval here would probably be more difficult to get right than actually using find with -exec. See e.g. Understanding the -exec option of `find`. Also, writing code that inserts quotes around text for the shell to use is almost always the wrong approach.

    – Kusalananda
    2 days ago













  • See BashFAQ #20: How can I find and safely handle file names containing newlines, spaces or both?

    – Gordon Davisson
    2 days ago











  • I have variables that span the processing of the filenames.

    – Steve Brandli
    2 days ago






  • 1





    If you really must loop over the output of find, then better to use a null-delimited while read loop as discussed here: Why is looping over find's output bad practice?

    – steeldriver
    2 days ago






  • 2





    You should update your question with your real-life issue. The issue that you have presented is easily solved with find ... -exec, or even just find ... -print.

    – Kusalananda
    2 days ago














-1












-1








-1








What I ultimately want is to iterate over a set of filenames using find and loop on that list. (Yes, I know I can use -exec in find, but I have reasons why this doesn't work for me.)



for file in $(find . -type f -print | sed -e 's/^\(.*\)$/\"\1\"/') ; do echo $file ; done


This does not work when the file names have spaces in them. The script above attempts to solve this problem by returning double-quotes around each filename. But apparently bash considers the double-quotes just part of the adjacent characters. When a file name is a b c, echo is run on "a, b, and c" rather than abc.



Is there way to get bash to word-split recognizing the double-quotes as special characters?










share|improve this question














What I ultimately want is to iterate over a set of filenames using find and loop on that list. (Yes, I know I can use -exec in find, but I have reasons why this doesn't work for me.)



for file in $(find . -type f -print | sed -e 's/^\(.*\)$/\"\1\"/') ; do echo $file ; done


This does not work when the file names have spaces in them. The script above attempts to solve this problem by returning double-quotes around each filename. But apparently bash considers the double-quotes just part of the adjacent characters. When a file name is a b c, echo is run on "a, b, and c" rather than abc.



Is there way to get bash to word-split recognizing the double-quotes as special characters?







bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Steve BrandliSteve Brandli

1345 bronze badges




1345 bronze badges
















  • Could you mention something about the reasons you allude to at the end of the first sentence? For the quotes to be recognised as quoting characters, the shell has to evaluate them. You do this with eval, for example. Otherwise, they are like any other characters without any special meaning. Using eval here would probably be more difficult to get right than actually using find with -exec. See e.g. Understanding the -exec option of `find`. Also, writing code that inserts quotes around text for the shell to use is almost always the wrong approach.

    – Kusalananda
    2 days ago













  • See BashFAQ #20: How can I find and safely handle file names containing newlines, spaces or both?

    – Gordon Davisson
    2 days ago











  • I have variables that span the processing of the filenames.

    – Steve Brandli
    2 days ago






  • 1





    If you really must loop over the output of find, then better to use a null-delimited while read loop as discussed here: Why is looping over find's output bad practice?

    – steeldriver
    2 days ago






  • 2





    You should update your question with your real-life issue. The issue that you have presented is easily solved with find ... -exec, or even just find ... -print.

    – Kusalananda
    2 days ago



















  • Could you mention something about the reasons you allude to at the end of the first sentence? For the quotes to be recognised as quoting characters, the shell has to evaluate them. You do this with eval, for example. Otherwise, they are like any other characters without any special meaning. Using eval here would probably be more difficult to get right than actually using find with -exec. See e.g. Understanding the -exec option of `find`. Also, writing code that inserts quotes around text for the shell to use is almost always the wrong approach.

    – Kusalananda
    2 days ago













  • See BashFAQ #20: How can I find and safely handle file names containing newlines, spaces or both?

    – Gordon Davisson
    2 days ago











  • I have variables that span the processing of the filenames.

    – Steve Brandli
    2 days ago






  • 1





    If you really must loop over the output of find, then better to use a null-delimited while read loop as discussed here: Why is looping over find's output bad practice?

    – steeldriver
    2 days ago






  • 2





    You should update your question with your real-life issue. The issue that you have presented is easily solved with find ... -exec, or even just find ... -print.

    – Kusalananda
    2 days ago

















Could you mention something about the reasons you allude to at the end of the first sentence? For the quotes to be recognised as quoting characters, the shell has to evaluate them. You do this with eval, for example. Otherwise, they are like any other characters without any special meaning. Using eval here would probably be more difficult to get right than actually using find with -exec. See e.g. Understanding the -exec option of `find`. Also, writing code that inserts quotes around text for the shell to use is almost always the wrong approach.

– Kusalananda
2 days ago







Could you mention something about the reasons you allude to at the end of the first sentence? For the quotes to be recognised as quoting characters, the shell has to evaluate them. You do this with eval, for example. Otherwise, they are like any other characters without any special meaning. Using eval here would probably be more difficult to get right than actually using find with -exec. See e.g. Understanding the -exec option of `find`. Also, writing code that inserts quotes around text for the shell to use is almost always the wrong approach.

– Kusalananda
2 days ago















See BashFAQ #20: How can I find and safely handle file names containing newlines, spaces or both?

– Gordon Davisson
2 days ago





See BashFAQ #20: How can I find and safely handle file names containing newlines, spaces or both?

– Gordon Davisson
2 days ago













I have variables that span the processing of the filenames.

– Steve Brandli
2 days ago





I have variables that span the processing of the filenames.

– Steve Brandli
2 days ago




1




1





If you really must loop over the output of find, then better to use a null-delimited while read loop as discussed here: Why is looping over find's output bad practice?

– steeldriver
2 days ago





If you really must loop over the output of find, then better to use a null-delimited while read loop as discussed here: Why is looping over find's output bad practice?

– steeldriver
2 days ago




2




2





You should update your question with your real-life issue. The issue that you have presented is easily solved with find ... -exec, or even just find ... -print.

– Kusalananda
2 days ago





You should update your question with your real-life issue. The issue that you have presented is easily solved with find ... -exec, or even just find ... -print.

– Kusalananda
2 days ago










0






active

oldest

votes














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f536166%2fbash-word-splitting-result-of-command-substitution-recognizing-returned-quotes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f536166%2fbash-word-splitting-result-of-command-substitution-recognizing-returned-quotes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...