I'm trying to determine if a tmux session exists by has-session
command.
If I have a session named abcdf:
adm@VirtualBox:/$ tmux -V
tmux 2.1
adm@VirtualBox:/$ tmux ls
abcdf: 1 windows (created Fri Feb 3 16:19:20 2017) [237x56] (attached)
has-session
command will return the session named a,ab,abc,abcd,abcdf is exist (error code=0)
adm@VirtualBox:/$ tmux has -t a
adm@VirtualBox:/$ echo $?
0
adm@VirtualBox:/$ tmux has -t ab
adm@VirtualBox:/$ echo $?
0
adm@VirtualBox:/$ tmux has -t abc
adm@VirtualBox:/$ echo $?
0
adm@VirtualBox:/$ tmux has -t abcd
adm@VirtualBox:/$ echo $?
0
adm@VirtualBox:/$ tmux has -t abcdf
adm@VirtualBox:/$ echo $?
0
adm@VirtualBox:/$
and the following is not exist (error code=1)
adm@VirtualBox:/$ tmux has -t b
can't find session b
adm@VirtualBox:/$ echo $?
1
adm@VirtualBox:/$ tmux has -t bc
can't find session bc
adm@VirtualBox:/$ echo $?
1
adm@VirtualBox:/$ tmux has -t bcd
can't find session bcd
adm@VirtualBox:/$ echo $?
1
It seems like this command will match the sessions by prefix-matching, is this correct? How do I search the session exact the name I want?
tmux list-session
and parse it withegrep
that is more controllable in term of parsing?tmux ls -F "#{session_name}"|grep -Fx $session >/dev/null
to search, but I'm still curious about this behavior since its manpage says: Report an error and exit with 1 if the specified session does not exist.list-session
too