转换Windows的OS X Bash脚本 [英] Translating OS X Bash Script for Windows
问题描述
我使用对冲转移神奇的灯笼在我的佳能5D Mark III上拍摄的视频文件.
I use Hedge to transfer Magic Lantern video files shot on my Canon 5D Mark III.
在OS X上,我可以使用Automator设置bash脚本,以执行mlv_dump 将文件从MLV传输到cDNG序列中.
On OS X, I'm able to use Automator to set up a bash script, to execute an mlv_dump to transfer the files from MLV into cDNG sequences.
我当前使用的脚本是:
cd "$(dirname "$1")"
for f in "$@"; do
if [[ -f $f ]]; then
filename=${f##*/};
folder=${filename%.*}
mkdir "${folder}";
~/mlv_dump --dng $f -o ${folder}/${folder}_;
fi
done
这可以轻松转换为Windows等效语言吗?
Can this easily translate into a Windows equivalent?
谢谢,
托马斯
Thanks,
Thomas
推荐答案
与编程语言之间的任何翻译一样,存在(a)一种 as-literal-as-possible 方法,该方法与(b),一种不是很明显但是很灵巧的目标语言方法.
(b)从长远来看始终是可取的.
As with any translation between programming languages, there's (a) an as-literal-as-possible approach, which contrasts with (b), an not-immediately-obvious-but-in-the-spirit-of-the-target-language approach.
(b) is always preferable in the long run.
使用PowerShell ,因为它是命令提示符"( cmd.exe
)及其批处理文件的继任者.以下代码尝试使用 PowerShell (v3 +语法)尝试(b).
Use PowerShell, because it is the - far superior - successor to the "Command Prompt" (cmd.exe
) and its batch files.
The code below is an attempt at (b), in PowerShell (v3+ syntax).
我鼓励您研究代码并在自己的答案中发布代码解释,以使其他人也可以从中受益.
I encourage you to study the code and post an explanation of it in an answer of your own, so that others may benefit too.
为帮助进行分析,请考虑以下资源:
To help with the analysis, consider the following resources:
This series of articles is a great, recipe-oriented introduction to PowerShell.
http://hyperpolyglot.org/shell 将类似POSIX的shell的语法并列,例如以 bash
的形式与 cmd.exe
的形式一起使用,并以简明的表格形式显示PowerShell.
http://hyperpolyglot.org/shell juxtaposes the syntax of POSIX-like shells such as bash
with that of cmd.exe
and PowerShell in concise, tabular form.
param(
[Parameter(Mandatory, ValueFromRemainingArguments)]
[System.IO.FileInfo[]] $LiteralPath
)
$outputBaseFolder = Split-Path -Parent $LiteralPath[0].FullName
foreach ($f in $LiteralPath) {
if ($f.exists) {
$outputFolder = Join-Path $outputBaseFolder $f.BaseName
New-Item -ItemType Directory $outputFolder
& "$HOME/mlv_dump" --dng $f.FullName -o "$outputFolder/$($f.BaseName)_"
} else {
Write-Warning "Item doesn't exist or is not a file: $($f.FullName)"
}
}
这篇关于转换Windows的OS X Bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!