你如何拆分长执行命令?

How do you split long exec commands up?

in ruby 当你在 capistrano 中编写部署脚本时,你可以使用 exec 到 运行 命令,但是当你有一个 exec 行时你会怎么做这么长:

exec 'bundle exec promiscuous publish "Xaaron::User.all" && bundle exec promiscuous publish "Xaaron::Role.all" && bundle exec promiscuous publish "Xaaron::Permission.all" && bundle exec promiscuous publish "Xaaron::ApiKey.all"'

它有效,它 运行s,它做我想做的,但我必须添加更多。而且有点长。那么我如何将它分成多行并仍然正常使用它 运行 呢?

您可以将字符串拆分成单独的行:

exec "bundle install && " +
     "apt-get install nginx && " +
     "cat file"

怎么样

exec [
  'bundle exec promiscuous publish "Xaaron::User.all"',
  'bundle exec promiscuous publish "Xaaron::Role.all"',
  'bundle exec promiscuous publish "Xaaron::Permission.all"',
  'bundle exec promiscuous publish "Xaaron::ApiKey.all"',
].join(" && ")

或者在这种情况下,

exec %w[User Role Permission ApiKey]
.map{|e| "bundle exec promiscuous publish \"Xaaron::#{e}.all\""}.join(" && ")