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*

8
  • 1
    +1 nice solution (and good question), but you should a) double-quote your variables, and b) use an array for $tmuxArguments - a single string var containing space separated options kind of works but is very fragile and inflexible (there are some things, esp involving args which need to be quoted, that are easy to do using array elements but very difficult with just a single string). e.g. sudo ip netns exec "$namespace" sudo -u "$USER" tmux -S "/tmp/$namespace.tmux" "${tmuxArguments[@]}" Commented Oct 7 at 5:00
  • 1
    I used to advise "Double-quote your variables except in the few rare instances when you know you want the shell to do word-splitting (e.g. to pass multiple args to a program)". Now my advice is "Always double quote your variables. Use an array where you might otherwise be tempted to rely on shell word-splitting (e.g. to pass multiple args to a program)" Commented Oct 7 at 5:00
  • @cas I use powershell, this isnt an issue. $var is always a single parameter, and if you deliberately want it expanded you have to do that consciously. If you tried to use the above example verbatim in my scripts, $tmuxArguments would just be a single string and wouldnt do much (basically only permitting a or new). No mention of bash in this post! Commented Oct 7 at 6:02
  • You can see I'm pretty diligent about that if I am forced to work within bash, even deliberately using single 's if I know no variables are meant to be interpreted at all Commented Oct 7 at 6:11
  • 1
    When using -S, tmux doesn't check the ownership and permission of the path components, so using a socket with a fixed name in a world writable directory is very unsafe and could allow another user on the system take over the account. Better would be to use the -L option instead. Commented Oct 7 at 6:13