ruby系统调用cp : missing destination file operand after

标签 ruby scripting terminal

我在 ruby​​ 脚本中有类似以下内容的内容:

from = "/path/to/script.rb"
to = "/path/to/destination/"
puts "Copying #{from} to #{to}"
system("cp #{from} #{to}")

这会在终端中提供以下输出:

copying /path/to/script.rb 
 to /path/to/destination/
cp: missing destination file operand after ‘/path/to/script.rb’
Try 'cp --help' for more information.

我在终端中运行以下命令没有问题:

cp /path/to/script.rb /path/to/destination

也不在 ruby​​ 脚本内:

system("cp /path/to/script.rb /path/to/destination")

任何关于如何更好地解决我的脚本问题的建议,或者正确方向的指针将不胜感激。

最佳答案

我正在从文件中读取内容,而不是修剪换行符。这应该从终端输出中显而易见(注意“to”之前的换行符和空格)。

更改自:

files = []
File.open(file-of-paths).read.each_line do |line|
 files.push(line)
end 

以下问题已解决:

files = []
File.open(file-of-paths).read.each_line do |line|
 files.push(line.chomp)
end 

关于ruby系统调用cp : missing destination file operand after,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26411424/

相关文章:

macos - 在 Mac OSX 上的终端中,如何使用 shift + 箭头来选择文本?

vim - Alt 键快捷键在使用 Vim 的 gnome 终端上不起作用

ruby - 如何使用 to_i 获取 Ruby 字符串中的第二个整数?

ruby - 使用macruby或ruby cocoa读取系统信息

linux - 在linux、bash中的单独列中回显2个变量

具有基本 if/else 和基于模式运行的进程计数的 Bash 脚本

ruby-on-rails - Rails 网站上的 UnknownAttributeError

c++ - 如何将 C++ 编译器标志添加到 extconf.rb

shell - Dash 变量扩展在某些情况下不起作用

node.js - Nodejs 中带有 `progress` 模块的堆叠进度条