我的系统是 Windows,我安装了 Cygwin,这样我就可以运行 shell 和 bash 文件。我在运行此处发布的第二个脚本时遇到了问题https://superuser.com/questions/169151来自@Biapy 并希望获得一些信息:
它没有告诉您有关脚本的命令行应该是什么样子的信息,所以我通过推理来运行它!
在脚本的开头,没有任何解释器定义,或者这不是强制性的?!我用和都进行了测试#!/bin/bash
,#!/bin/sh
但遇到了同样的问题:
注意:该脚本与它将读取的输入文件位于同一目录中。
运行脚本时无需输入输入文件的完整路径,因为它们与脚本位于同一目录中:
sh script.sh "audio.ogg" "Cover.jpeg"
输出脚本:
script.sh: line 7: local: can only be used in a function
script.sh: line 8: : No such file or directory
sed: can't read : No such file or directory
script.sh: line 18: local: can only be used in a function
script.sh: line 19: local: can only be used in a function
script.sh: line 22: : No such file or directory
script.sh: line 25: : No such file or directory
script.sh: line 29: : No such file or directory
script.sh: line 32: : No such file or directory
script.sh: line 35: : No such file or directory
script.sh: line 38: : No such file or directory
script.sh: line 40: : No such file or directory
script.sh: line 43: : No such file or directory
script.sh: line 46: : No such file or directory
script.sh: line 49: : No such file or directory
script.sh: line 54: : No such file or directory
wc: /path/to/my-cover-art.jpg: No such file or directory
script.sh: line 57: : No such file or directory
script.sh: line 59: : No such file or directory
script.sh: line 59: : No such file or directory
Error opening input file '/path/to/my-ogg-file.ogg'.
rm: cannot remove '': No such file or directory
rm: cannot remove '': No such file or directory
运行脚本并输入输入文件的完整路径:
sh script.sh "C:/Users/CMG/Desktop/audio.ogg" "C:/Users/CMG/Desktop/Cover.jpeg"
输出脚本:
script.sh: line 7: local: can only be used in a function
script.sh: line 8: : No such file or directory
sed: can't read : No such file or directory
script.sh: line 18: local: can only be used in a function
script.sh: line 19: local: can only be used in a function
script.sh: line 22: : No such file or directory
script.sh: line 25: : No such file or directory
script.sh: line 29: : No such file or directory
script.sh: line 32: : No such file or directory
script.sh: line 35: : No such file or directory
script.sh: line 38: : No such file or directory
script.sh: line 40: : No such file or directory
script.sh: line 43: : No such file or directory
script.sh: line 46: : No such file or directory
script.sh: line 49: : No such file or directory
script.sh: line 54: : No such file or directory
wc: /path/to/my-cover-art.jpg: No such file or directory
script.sh: line 57: : No such file or directory
script.sh: line 59: : No such file or directory
script.sh: line 59: : No such file or directory
Error opening input file '/path/to/my-ogg-file.ogg'.
rm: cannot remove '': No such file or directory
rm: cannot remove '': No such file or directory
两次测试都存在同样的问题:
local: can only be used in a function
No such file or directory
另一个问题是:
当音频名称带有感叹号时,脚本在开始之前就会取消,如下所示:
运行带有感叹号的音频名称的脚本:
sh script.sh "audio!.ogg" "Cover.jpeg"
输出脚本:
-bash: !.ogg: event not found
但是,如果我通过在输入文件中放置单引号来运行脚本,-bash 错误就会消失,并且会返回到初始错误。
运行带有感叹号的音频名称的脚本,在输入文件中加上单引号:
sh script.sh 'audio!.ogg' 'Cover.jpeg'
输出脚本:
script.sh: line 7: local: can only be used in a function
script.sh: line 8: : No such file or directory
sed: can't read : No such file or directory
script.sh: line 18: local: can only be used in a function
script.sh: line 19: local: can only be used in a function
script.sh: line 22: : No such file or directory
script.sh: line 25: : No such file or directory
script.sh: line 29: : No such file or directory
script.sh: line 32: : No such file or directory
script.sh: line 35: : No such file or directory
script.sh: line 38: : No such file or directory
script.sh: line 40: : No such file or directory
script.sh: line 43: : No such file or directory
script.sh: line 46: : No such file or directory
script.sh: line 49: : No such file or directory
script.sh: line 54: : No such file or directory
wc: /path/to/my-cover-art.jpg: No such file or directory
script.sh: line 57: : No such file or directory
script.sh: line 59: : No such file or directory
script.sh: line 59: : No such file or directory
Error opening input file '/path/to/my-ogg-file.ogg'.
rm: cannot remove '': No such file or directory
rm: cannot remove '': No such file or directory
@Biapy 能帮忙吗?
笔记:
我已经在我的系统上运行其他脚本,没有任何问题。