bash – 如何启动tmux与几个窗口在不同的目录?
我想使用一个脚本打开一个tmux会话有6个窗口,每个在不同的目录。我开始与
a script I found和尝试这第一:
tmux new-session -s xyz -n etc -d 'cd /etc' tmux new-window -t xyz:1 -n var 'cd /var/log' 但我很快发现,这将不会像我预期的工作 – 窗口将在shell命令完成后关闭。 所以我的下一个想法是开始一个新的shell,像这样: tmux new-session -s xyz -n etc -d 'cd /etc; bash -i' tmux new-window -t xyz:1 -n var 'cd /var/log; bash -i' tmux new-window -t xyz:2 -n var2 'cd /var/log; bash -i' tmux new-window -t xyz:3 -n var3 'cd /var/log; bash -i' tmux new-window -t xyz:4 -n var4 'cd /var/log; bash -i' tmux new-window -t xyz:5 -n var5 'cd /var/log; bash -i' tmux new-window -t xyz:6 -n var6 'cd /var/log; bash -i' tmux select-window -t xyz:1 tmux -2 attach-session -t xyz 这几乎工作。但如果我启动超过约4个窗口,我经常看到下面的bash错误在其中一个窗口启动后: bash: [: =: unary operator expected bash: [: too many arguments bash: [: =: unary operator expected bash: [: =: unary operator expected bash: [: =: unary operator expected bash: [: =: unary operator expected bash: [: too many arguments bash: [: =: unary operator expected bash: [: =: unary operator expected bash: [: =: unary operator expected bash: [: =: unary operator expected bash: [: =: unary operator expected 我不知道为什么会发生这种情况,但我仍然认为我不这样做。有没有更好的方式来设置一个tmux会话在几个目录?
shell错误可能是由于您的启动文件(或他们运行的某些问题)。
作为shellter的评论,临时包括命令集-vx早在您的启动序列是一个很好的方法来找出错误发生在哪里。 >将.bashrc的echo start和.bashrc的echo end放在.bashrc的开始/结尾,以查看.bashrc是否发生错误。如果没有,请测试其他启动文件:.bash_profile / .bash_login / .profile。如果错误发生在该文件之前,则问题可能在/ etc / profile中。 注意:这些调试添加需要是临时的,因为如果你使用一个自动登录的程序(例如rsync,基于SSH的Git访问等),因为这些程序需要一个“干净”的连接没有这样的调试噪声当下。 应该没有必要使用cd命令像shell-command参数给tmux new-session或tmux新窗口。 当从命令行使用新会话和新窗口时(即通过tmux二进制文件,而不是通过绑定或在tmux-:提示符下),新窗口将“继承”当前工作目录。根据CHANGES文件,看起来像这样的情况,因为tmux 0.6(至少对于新窗口)。 ?这是tmux介导的继承,而不是父子继承,这是通过cwd的通常机制。 这个脚本适用于我与tmux 1.5: #!/bin/bash # var for session name (to avoid repeated occurences) sn=xyz # Start the session and window 0 in /etc # This will also be the default cwd for new windows created # via a binding unless overridden with default-path. cd /etc tmux new-session -s "$sn" -n etc -d # Create a bunch of windows in /var/log cd /var/log for i in {1..6}; do tmux new-window -t "$sn:$i" -n "var$i" done # Set the default cwd for new windows (optional,otherwise defaults to session cwd) #tmux set-option default-path / # Select window #1 and attach to the session tmux select-window -t "$sn:1" tmux -2 attach-session -t "$sn" 这也可能(作为副作用)缓解您的shell启动错误,因为tmux启动shell不同于纯bash -i(它更类似于bash -l,它使用.bash_profile / .bash_login /。配置文件而不是(只)你的.bashrc)。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |