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"'
它有效,它运行,它做我想要的,但我必须添加更多。它有点长。那么如何将其分解为多行并仍使其正常运行?
答案 0 :(得分:4)
怎么样?
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(" && ")
答案 1 :(得分:2)
您可以将字符串拆分为单独的行:
exec "bundle install && " +
"apt-get install nginx && " +
"cat file"