Hi All,
for a script I'm writing I need to be able to put the following command in a variable:
tail -30 <file> | egrep "JBoss \(MX MicroKernel\) .* Started"
I thought surround it with single quotes would work. However, it doesnt escape the wildcard, and results in the wildcard being expanded with local files beginning with "."
I've tried a hundred other ways to get this to work. Also some ways result in the correct results when i run echo $containingVar but running the command from the variable gives me this
$var
tail: invalid option -- 3
Try `tail --help' for more information.
while entering it as it appears works fine. This one has been driving me crazy so any help would be appreciated!
How are you exactly initialising the variable "var"? Could you please post the exact line you're using?
various different ways: Here's the line that In my opinion should work:
$serverCheck='tail -30 /dir1/dir2/dir3/file.log | egrep "JBoss \(MX MicroKernel\) .* Started"'
Do you want result in variable "serverCheck" or are you evaluating variable "serverCheck" ?
If you want result in "serverCheck" then use
serverCheck=$(tail -30 /dir1/dir2/dir3/file.log | egrep "JBoss \(MX MicroKernel\) .* Started")
No. I need the resulting command stored in the variable. Not the result.
I invoke it with
$serverCheck
in another part of the script
Rmove sign "$" from the serverCheck
serverCheck='tail -30 /dir1/dir2/dir3/file.log | egrep "JBoss \(MX MicroKernel\) .* Started"'
thats the same code I wrote above. It doesn't work. The wildcard is expanded to include locale files. I use the '$' only when I want to call the resulting command.
---------- Post updated at 08:55 AM ---------- Previous update was at 08:55 AM ----------
my mistake. that's not what i wrote above. But above was a typo. I didn't put a '$'. Instead I've been putting what you wrote. Still doesnt work.
You need to evaluate $serverCheck like below
eval $serverCheck
Instead of using only $serverCheck
Found away around this problem by using
and changing my logic elsewhere. This solution is not ideal and I'm still curious as to what was going wrong with