Tailscale -up over multiple lines

When running the tailscale command on my subnet router that is an exit node, I have to advertise quite a few routes. This makes the command hard to read and edit.

Is it possible to split the command over multiple lines, or use a configuration file for this?

example:

tailscale up --advertise-routes=10.6.4.0/24,10.6.5.0/24,8.8.8.8/32,1.1.1.1/32,192.168.4.12 --accept-routes

The usual way to do this in the shell is to use a backslash to escape the newline:

tailscale up \
    --advertise-routes=10.6.4.0/24,10.6.5.0/24,8.8.8.8/32,1.1.1.1/32,192.168.4.12 \
    --accept-routes

Yes, I guess that’s an option, but since it failes in case of whitespace, that doesn’t really make it more readable.

tailscale up --advertise-routes=\
    10.6.4.0/24,\
    10.6.5.0/24,\
    8.8.8.8/32,\
    1.1.1.1/32,\
    192.168.4.12 \
    --accept-routes

… would be a bit better (although the backslashes are still ugly), but that fails.

It has to be like this:

tailscale up --advertise-routes=\
10.6.4.0/24,\
10.6.5.0/24,\
8.8.8.8/32,\
1.1.1.1/32,\
192.168.4.12 \
    --accept-routes

I was hoping there was a better way to do this.

At the risk of becoming a bit StackOverflow and assuming you are happy with a bit of bash, what about:

declare -a routes=(
    10.6.4.0/24
    10.6.5.0/24
    8.8.8.8/32
    1.1.1.1/32
    192.168.4.12
)
tailscale up --accept-routes \
    --advertise-routes="$(IFS=, ; echo "${routes[*]}")"
1 Like