2

I was looking for a good workaround for keeping my .tmux.conf file consistent across systems (I have both OS X and Ubuntu and they have different techniques for copy/paste support) when I came across this comment that offered a solution: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/issues/8#issuecomment-4134987

But before I use the code snippet in the comment, I'd like to fully understand what it's doing. In particular, I don't quite understand the last line, and the bash man page for parameter substitution didn't help much.

This is the line:

exec /path/to/actual/tmux ${cfg+-f "$cfg"} "$@"

Specifically, what does the ${cfg+-f "$cfg"} part mean?

3cheesewheel
  • 9,133
  • 9
  • 39
  • 59

2 Answers2

4

It means to skip the parameter if it is not set. In effect resulting in one of:

exec /path/to/actual/tmux -f "/some/cfg" "$@"
exec /path/to/actual/tmux "$@"

So if $cfg is set, -f "$cfg" is used, otherwise nothing, so tmux does not complain about a missing parameter for -f.

lynxlynxlynx
  • 1,371
  • 17
  • 26
1

It means that if the variable cfg is set, it would expand with the combined value of -f "$cfg".

Example:

> a=1234
> echo "${a+b}" # => variable is set
b
> a=
> echo "${a+b}" # => empty but still set would still expand it.
b
> unset a
> echo "${a+b}" # => it's now unset so no output
(nothing)

Another with an extra variable:

> a=1234
> x=y
> echo "${a+b "$x"}"
b y
> echo "${a+"$a $x"}"
1234 y
konsolebox
  • 72,135
  • 12
  • 99
  • 105