目前我正在执行一项任务,我必须在其中读取压缩文件并列出其内容。我在我的 Controller 文件中使用 bash 脚本代码 files = tar tf 3578336.tar.xz | awk -F'/' '{ for (i=1;i<5;i++) print "/"$i ; print "\n"}' ORS='' |grep "/"|uniq
.我正在尝试使用此命令获取内容,但我无法获取变量中的响应。如果我使用 files = tar tf 3578336.tar.xz
然后它返回所有内容。我要做的是根据级别列出目录和文件。这就像为压缩文件创建文件管理系统。
如有任何帮助,我们将不胜感激。
最佳答案
您能否发布一些示例输入/输出数据,看看您想要什么?
我附近没有 *nix,但您可以检查 tar 是否正在将输出写入 stderr 或 stdout,如下所示:
tar tf 3578336.tar.xz 2>/dev/null #If you can see the filenames, then it writes to stdout
tar tf 3578336.tar.xz >/dev/null #If you can see the filenames, then it writes to stderr
关于ruby-on-rails - 为什么 'awk' 命令在 Ruby on Rails 中使用时不向变量返回任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37698369/