Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • I think OP gave us a minimal working example. and reals OP's shell is more complex, echo ${GetValue} would be show as a residual token, while actual shell might use it. Commented Jul 22, 2021 at 14:03
  • @Archemar There is no indication that the code in the question is a minimal working example. In fact, the text explicitly says "Below is the piece of code with problematic grep", which makes me assume that this is the actual code they are using (the inclusion of tee -a also would not be part of a minimal working example). In any case, there is no other code in the question so this is all I have to go on. If the user needs to save the output of the awk in a variable, it would be easy to put my pipeline in a command substitution. Commented Jul 22, 2021 at 14:48
  • @Kusalananda - i have a lot of code which needs to execute on multiple remote hosts. Part of business requirement. Have achieved executing commands on remote hosts using <<-EOF in one of other scripts. Not sure why the hell this one has issues. Anyways script runs in a loop to cover all the remote hosts to grep keyword in their respective log directories. What I have posted is just the first line of code after ssh where it fails. What remains after this are too many validations to be done. This also rules out the solution to use ssh to get the data, then run the commands locally on that data. Commented Jul 22, 2021 at 17:38
  • @user15762223 I don't quite see why the validations need to happen remotely though. That just complicates the code. In any case, as both I and the other person have noted, the issue is due to not quoting the here-document. You would do that by using <<'EOF' to start the here-document. Commented Jul 22, 2021 at 17:44
  • @Kusalananda - using <<'EOF' fails script and returns syntax error - unexpected end of file. As I see it, quoting EOF disables all my code below it. It also does not allows variable expansion on remote hosts as I read somewhere. Tried this also << 'EOF' but no luck. As I mentioned, I wrote a different script for some other project requirement to connect to remote hosts and do some actions, it worked fine using ssh and <<-EOF. I just had to use $(declare -p variable) that were to be used on remote hosts. Tried using declare in this case, but strangely it's not working. Commented Jul 22, 2021 at 18:05