如何创建并运行 bash 文件?
如何创建 bash 文件?
我发现以下 bash 脚本。
#!/bin/bash
for f in *.wav; do
echo "Processing $f file..."
afconvert -f caff -d LEI16@44100 -c 1 "$f" "${f/wav/caf}"
done
我有 Mac
和 Windows
。
但我不知道我必须把它放在哪里以及如何运行这个脚本?
How to create a bash file?
I found following bash script.
#!/bin/bash
for f in *.wav; do
echo "Processing $f file..."
afconvert -f caff -d LEI16@44100 -c 1 "$f" "${f/wav/caf}"
done
I have Mac
and Windows
.
But I don't know where I have to put this and how I can run this script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需将文本保存到名为
my_bash_script
的文件中,使其可执行并从命令行运行它,如下所示:根据文件判断,它需要位于包含 *.wav 文件的目录中。
Just save the text into a file called
my_bash_script
a file, make it executable and run it from the command line like this:Judging by the file it will need to be in a directory containing *.wav files.
由于您有两种不同的操作系统设置,我将把我的答案分为两部分。
首先:Windows
Windows 没有 Bash 解释器,也没有上面代码尝试运行的
afconvert
程序。最好的选择是使用 Cygwin 在 Windows 上安装 Unix 控制台。我也不知道你可以从哪里获得afconvert
。OSX
OSX 确实有一个控制台和 afconvert 软件(至少我的 OSX 有)。您只需将文件放入文件夹中并为其指定一个以
.sh
结尾的名称即可。然后你应该能够运行它。As you have two different OS setup, I will split my answer in two parts.
First: Windows
Windows does not have a Bash interpreter, nor the
afconvert
program the code above is trying tu run. Your best bet will be to use Cygwin to install a Unix console on your Windows. Also I don't know, where you could getafconvert
from.OSX
OSX does have a console and the
afconvert
software (at least my OSX does). You can simply drop the file in a folder and give it a name ending in.sh
. Then you should be able to run it.只需将文本粘贴到纯文本文件中,然后将其标记为可执行文件:
要运行它:
Just paste the text into a plaint text file and then mark it as executable:
To run it:
将脚本放置在您拥有 .wav 文件的任何位置。当此处给出休整指示时:
http://tldp.org/LDP/Bash-Beginners-Guide /html/sect_02_01.html#sect_02_01_03
Place the script anywhere you have your .wav files. When fallow instructions given here:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_01.html#sect_02_01_03