在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"'它工作,它运行,它做我想做的,但我必须增加更多。而且有点长。那么,如何将其分解为多行,并使其仍能正常运行?
发布于 2015-01-21 05:51:18
您可以将字符串拆分成不同的行:
exec "bundle install && " +
"apt-get install nginx && " +
"cat file"发布于 2015-01-21 06:04:02
关于
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(" && ")https://stackoverflow.com/questions/28060422
复制相似问题