Originally Posted by gearge
I want to assign the following section to a variable, for later reference and/or modification:
How can I do this?
The simple answer is...you don't!
Variables are designed for containing data
, not code. Pipes and redirections in particular cannot be handled this way except through the use of eval
, and eval
has security implications.
If you want a way store a command dynamically then you should use a function. That's what they were designed for.
See here for a detailed discussion:
Second, as grail pointed out, don't parse ls
for filenames. Use a globbing
pattern or find
; and store the results in an array
if you need to process the entries more than once or in an arbitrary order.
And again, if you would explain exactly what your actual goal
is, and give us some examples of the input and desired output, we'll be glad to help you find a more workable solution.