2

When I execute the command screen -S myscreen -X stuff $'search add $1 \015' from a shell it works perfectly. If I put it in a .sh file and run it as sh /test.sh variablehere it sends it to screen as $'search add variablehere'.

Why would it normally work but not from sh? Im on Ubuntu Server if it matters.

nosedive25
  • 123
  • 4
  • Found a solution, still not sure why it refused to work. http://unix.stackexchange.com/questions/5847/why-is-screen-seemingly-doing-nothing-with-commands-passed-with-x – nosedive25 Aug 21 '11 at 23:21
  • Could you post this as an answer? So that you can accept it when possible and "close" the question. – nopcorn Aug 22 '11 at 00:12
  • The problem in the other question appears to be different to me. If it "solved" your problem it's only because it sidestepped your issue, which seems to be that bash != sh. You can't do fancy stuff in bash and exect it to work the same in a different shell, but you can build and run scripts with bash so it should be an easy fix. – Caleb Aug 22 '11 at 08:09
  • @MaxMackie, I did but it added it as a comment. No need to now as enzotib provided a good explanation of not only how to fix the issue but why it happened. – nosedive25 Aug 23 '11 at 02:22

1 Answers1

2

The expression $'search add $1 \015', and in general the quoting $'string' is a bash features (probably also of other shells), so it works from command line, where you probably are using bash.

It for sure do not work for sh, that in ubuntu points to dash.

So the simple solution is to invoke your script with bash ./test.sh.

enzotib
  • 51,661