1
I'm struggling to find some way to express this in some other fashion that will yield the appropriate output:
var="$(ls /var/run/ | grep searchterm | awk {'NR == 2'})"
I've seen on places like shellcheck to use a glob or loop but my research so far hasn't come up with anything to do it so that I can get the result as a variable rather than just echoing or printing the content.
Are there any methods to do this?
What is your end goal that you wish to accomplish with capturing this information into a shell variable? If you edit and expand your question to cover why you want to do this, the answer may become clearer. Thank you. – StandardEyre – 2016-12-10T04:23:19.970
It is part of a custom Icinga plugin I am writing for myself.
There is 4 files in the directory - 3 have static names - 1 doesn't. I need to evaluate the contents of these files for the plugin.
The non-statically named file does have some part of the file name that is static to itself and separate from the rest which is what the grep searchterm is.
The variable itself is used to take some other actions later. – Jarrad S – 2016-12-10T04:26:47.790
(1) Why are you doing
NR == 2
? (2) If you useawk
, you should put the entireawk
program in quotes; e.g.,'{NR == 2}'
, with the curly braces inside the quotes. – G-Man Says 'Reinstate Monica' – 2016-12-17T03:23:58.720