How to write a shell script that starts tmux session, and then runs a ruby script

后端 未结 6 684
暗喜
暗喜 2020-12-08 03:53

I want to write a shell script that does this:

  • First, create a tmux session
  • Second, run a ruby script called \"run.rb\" INSIDE the tmux session
  • <
6条回答
  •  孤城傲影
    2020-12-08 04:34

    If you want to keep your tmux session alive after starting some commands, a possible solution is to start a bash with an init file:

    tmux new -d -s mysession "bash --init-file foo.script"
    

    where foo.script would contain your commands. Alternatively, you can feed the command to the shell directly from the command line:

    tmux new -d -s mysession2 "bash --init-file <(echo ruby run.rb)"
    

    Note that --init-file was meant for reading system wide initialization files like /etc/bash.bashrc so you might want to 'source' these in your script.

提交回复
热议问题