Having a terrible problem with quotes/single quotes!

Hello. I'm trying to write a bash script that uses GNU screen and have hit a brick wall that has cost me many hours... (I'm sure it has something to do with quoting/globbing, which is why I post it here)

I can make a script that does the following just fine:

test.sh:

#!/bin/bash

# make a screen session named blah with a window named "dummy"
screen -dmS blah -t dummy
# and give it a specific hardstatus line
screen -r blah -X hardstatus on
screen -r blah -X hardstatus alwayslastline
screen -r blah -X hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m/%d/%y %{W}%c %{g}]'

# lastly, add a window, dummy2
screen -d -r blah -X screen -t dummy2

A simple `screen -r blah` will show it worked well! I have a pretty hardstatus line that shows the hostname, windownames, and dates.

Now I want to wrap the screen commands into a Launch command...

test2.sh:

#!/bin/bash

Launch()
{
     local cmd=$1
     local res
 
     res=$($cmd)


    echo $res
}



# make a screen session named blah with a window named "dummy"
Launch "screen -dmS blah -t dummy"
# and give it a specific hardstatus line
Launch "screen -r blah -X hardstatus on"
Launch "screen -r blah -X hardstatus alwayslastline"
Launch "screen -r blah -X hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=  kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}  %m/%d/%y %{W}%c %{g}]'"

# lastly, add a window, dummy2
Launch "screen -d -r blah -X screen -t dummy2"

if you do a `screen -r blah`now...
Most everything worked - it created the "blah" screen session, and even created the "dummy" and "dummy 2" windows.. But look at the status line, its just a blank white bar!

what am I doing wrong? This is killing me!

I don't use screen, so I'm not at all familiar with it. However, as you suspect, that command substitution will not properly handle the single quotes nor the glob characters (e.g. *, ?, [...], etc) in that screen command-string argument.

As long as it's trusted input, you can try: res=$(eval "$cmd")

Regards,
Alister

Thanks, that worked great!