find command with variable in itHow can we run a command stored in a variable?Why Bash unable to find command...

Filtering fine silt/mud from water (not necessarily bacteria etc.)

Construct a pentagon avoiding compass use

Do native speakers use ZVE or CPU?

What does "Fotze" really mean?

Is it rude to tell recruiters I would only change jobs for a better salary?

Why limit to revolvers?

Should you avoid redundant information after dialogue?

What are some symbols representing peasants/oppressed persons fighting back?

Why is dry soil hydrophobic? Bad gardener paradox

Players of unusual orchestral instruments

Why did my rum cake turn black?

What to put after taking off rear stabilisers from child bicyle?

Find values of x so that the matrix is invertible

How do I write a romance that doesn't look obvious

What is this welding tool I found in my attic?

How might the United Kingdom become a republic?

Professor falsely accusing me of cheating in a class he does not teach, two months after end of the class. What precautions should I take?

TikZ Can I draw an arrow by specifying the initial point, direction, and length?

How to remove " 's" in a string?

Why do they not say "The Baby"

Why does the autopilot disengage even when it does not receive pilot input?

Too many spies!

Modeling, view and projection transformation using vector and point in homogenous form

Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?



find command with variable in it


How can we run a command stored in a variable?Why Bash unable to find command even if $PATH is specified properly?echo string >> file does not workHow do I change working directories with KDialog?How do you assign {} to a variable in find --execWhy can't my Unix terminal not find my matlab binaries and making Unix find them again?Obtain script current directory (so that I can do include files without relative paths and run the script from everywhere)Preform operation in bash only if a variable is less than a second variableUse asterisk in variablesFind command - file path with white spaceBash: I have a variable in bash script;






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







1















I want to do this: readarray var1 < <(find "/path/to/dir" ( $var2 ) | sort)



echo $var2
user@domain:~# -name "*.avi" -o -name "*.mkv"


Unfortunately, my script does not work. Please, tell me where I do a mistake.










share|improve this question

























  • I'd be interested in why you need the sorting of the results. You cold get this in the zsh shell in a much more convenient and safe way which would not rely on the pathnames being sane (containing no newlines).

    – Kusalananda
    2 hours ago











  • @Kusalananda Just I'm newer in Linux (more precisely in Ubuntu). if you are telling me that your case is better I will be glad to see it.

    – UnixUser
    2 hours ago


















1















I want to do this: readarray var1 < <(find "/path/to/dir" ( $var2 ) | sort)



echo $var2
user@domain:~# -name "*.avi" -o -name "*.mkv"


Unfortunately, my script does not work. Please, tell me where I do a mistake.










share|improve this question

























  • I'd be interested in why you need the sorting of the results. You cold get this in the zsh shell in a much more convenient and safe way which would not rely on the pathnames being sane (containing no newlines).

    – Kusalananda
    2 hours ago











  • @Kusalananda Just I'm newer in Linux (more precisely in Ubuntu). if you are telling me that your case is better I will be glad to see it.

    – UnixUser
    2 hours ago














1












1








1








I want to do this: readarray var1 < <(find "/path/to/dir" ( $var2 ) | sort)



echo $var2
user@domain:~# -name "*.avi" -o -name "*.mkv"


Unfortunately, my script does not work. Please, tell me where I do a mistake.










share|improve this question
















I want to do this: readarray var1 < <(find "/path/to/dir" ( $var2 ) | sort)



echo $var2
user@domain:~# -name "*.avi" -o -name "*.mkv"


Unfortunately, my script does not work. Please, tell me where I do a mistake.







bash shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 46 mins ago









steeldriver

40.8k4 gold badges56 silver badges93 bronze badges




40.8k4 gold badges56 silver badges93 bronze badges










asked 3 hours ago









UnixUserUnixUser

274 bronze badges




274 bronze badges













  • I'd be interested in why you need the sorting of the results. You cold get this in the zsh shell in a much more convenient and safe way which would not rely on the pathnames being sane (containing no newlines).

    – Kusalananda
    2 hours ago











  • @Kusalananda Just I'm newer in Linux (more precisely in Ubuntu). if you are telling me that your case is better I will be glad to see it.

    – UnixUser
    2 hours ago



















  • I'd be interested in why you need the sorting of the results. You cold get this in the zsh shell in a much more convenient and safe way which would not rely on the pathnames being sane (containing no newlines).

    – Kusalananda
    2 hours ago











  • @Kusalananda Just I'm newer in Linux (more precisely in Ubuntu). if you are telling me that your case is better I will be glad to see it.

    – UnixUser
    2 hours ago

















I'd be interested in why you need the sorting of the results. You cold get this in the zsh shell in a much more convenient and safe way which would not rely on the pathnames being sane (containing no newlines).

– Kusalananda
2 hours ago





I'd be interested in why you need the sorting of the results. You cold get this in the zsh shell in a much more convenient and safe way which would not rely on the pathnames being sane (containing no newlines).

– Kusalananda
2 hours ago













@Kusalananda Just I'm newer in Linux (more precisely in Ubuntu). if you are telling me that your case is better I will be glad to see it.

– UnixUser
2 hours ago





@Kusalananda Just I'm newer in Linux (more precisely in Ubuntu). if you are telling me that your case is better I will be glad to see it.

– UnixUser
2 hours ago










1 Answer
1






active

oldest

votes


















2














Use an array:



var2=( -name "*.avi" -o -name "*.mkv" )

readarray var1 < <(find "/path/to/dir" ( "${var2[@]}" ) | sort)


See the somewhat related How can we run a command stored in a variable?






share|improve this answer


























  • Can I do it without array? Only variable. Is it possibly?

    – UnixUser
    2 hours ago













  • @UnixUser You'd better let us know why you wouldn't want to use an array. Using an array is the correct way of handling this.

    – Kusalananda
    2 hours ago











  • ... you're already using an array for var1, so it's not like you could port this code to a shell that doesn't support arrays

    – steeldriver
    2 hours ago











  • Thanks. You help me.

    – UnixUser
    2 hours ago











  • @Kusalananda I want to understand what options I have. Thanks too.

    – UnixUser
    2 hours ago














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%2f530030%2ffind-command-with-variable-in-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Use an array:



var2=( -name "*.avi" -o -name "*.mkv" )

readarray var1 < <(find "/path/to/dir" ( "${var2[@]}" ) | sort)


See the somewhat related How can we run a command stored in a variable?






share|improve this answer


























  • Can I do it without array? Only variable. Is it possibly?

    – UnixUser
    2 hours ago













  • @UnixUser You'd better let us know why you wouldn't want to use an array. Using an array is the correct way of handling this.

    – Kusalananda
    2 hours ago











  • ... you're already using an array for var1, so it's not like you could port this code to a shell that doesn't support arrays

    – steeldriver
    2 hours ago











  • Thanks. You help me.

    – UnixUser
    2 hours ago











  • @Kusalananda I want to understand what options I have. Thanks too.

    – UnixUser
    2 hours ago
















2














Use an array:



var2=( -name "*.avi" -o -name "*.mkv" )

readarray var1 < <(find "/path/to/dir" ( "${var2[@]}" ) | sort)


See the somewhat related How can we run a command stored in a variable?






share|improve this answer


























  • Can I do it without array? Only variable. Is it possibly?

    – UnixUser
    2 hours ago













  • @UnixUser You'd better let us know why you wouldn't want to use an array. Using an array is the correct way of handling this.

    – Kusalananda
    2 hours ago











  • ... you're already using an array for var1, so it's not like you could port this code to a shell that doesn't support arrays

    – steeldriver
    2 hours ago











  • Thanks. You help me.

    – UnixUser
    2 hours ago











  • @Kusalananda I want to understand what options I have. Thanks too.

    – UnixUser
    2 hours ago














2












2








2







Use an array:



var2=( -name "*.avi" -o -name "*.mkv" )

readarray var1 < <(find "/path/to/dir" ( "${var2[@]}" ) | sort)


See the somewhat related How can we run a command stored in a variable?






share|improve this answer















Use an array:



var2=( -name "*.avi" -o -name "*.mkv" )

readarray var1 < <(find "/path/to/dir" ( "${var2[@]}" ) | sort)


See the somewhat related How can we run a command stored in a variable?







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 hours ago

























answered 3 hours ago









steeldriversteeldriver

40.8k4 gold badges56 silver badges93 bronze badges




40.8k4 gold badges56 silver badges93 bronze badges













  • Can I do it without array? Only variable. Is it possibly?

    – UnixUser
    2 hours ago













  • @UnixUser You'd better let us know why you wouldn't want to use an array. Using an array is the correct way of handling this.

    – Kusalananda
    2 hours ago











  • ... you're already using an array for var1, so it's not like you could port this code to a shell that doesn't support arrays

    – steeldriver
    2 hours ago











  • Thanks. You help me.

    – UnixUser
    2 hours ago











  • @Kusalananda I want to understand what options I have. Thanks too.

    – UnixUser
    2 hours ago



















  • Can I do it without array? Only variable. Is it possibly?

    – UnixUser
    2 hours ago













  • @UnixUser You'd better let us know why you wouldn't want to use an array. Using an array is the correct way of handling this.

    – Kusalananda
    2 hours ago











  • ... you're already using an array for var1, so it's not like you could port this code to a shell that doesn't support arrays

    – steeldriver
    2 hours ago











  • Thanks. You help me.

    – UnixUser
    2 hours ago











  • @Kusalananda I want to understand what options I have. Thanks too.

    – UnixUser
    2 hours ago

















Can I do it without array? Only variable. Is it possibly?

– UnixUser
2 hours ago







Can I do it without array? Only variable. Is it possibly?

– UnixUser
2 hours ago















@UnixUser You'd better let us know why you wouldn't want to use an array. Using an array is the correct way of handling this.

– Kusalananda
2 hours ago





@UnixUser You'd better let us know why you wouldn't want to use an array. Using an array is the correct way of handling this.

– Kusalananda
2 hours ago













... you're already using an array for var1, so it's not like you could port this code to a shell that doesn't support arrays

– steeldriver
2 hours ago





... you're already using an array for var1, so it's not like you could port this code to a shell that doesn't support arrays

– steeldriver
2 hours ago













Thanks. You help me.

– UnixUser
2 hours ago





Thanks. You help me.

– UnixUser
2 hours ago













@Kusalananda I want to understand what options I have. Thanks too.

– UnixUser
2 hours ago





@Kusalananda I want to understand what options I have. Thanks too.

– UnixUser
2 hours ago


















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%2f530030%2ffind-command-with-variable-in-it%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...