为 Windows 翻译 OS X Bash 脚本 [英] Translating OS X Bash Script for Windows

查看:21
本文介绍了为 Windows 翻译 OS X Bash 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Hedge 来转移 Magic Lantern 视频文件是在我的佳能 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) 及其批处理文件的后继者.
下面的代码是对 (b) 的尝试,在 PowerShell(v3+ 语法)中.

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:

这个系列文章是对 PowerShell 的出色的、面向食谱的介绍.

This series of articles is a great, recipe-oriented introduction to PowerShell.

http://hyperpolyglot.org/shell 并列了类似 POSIX 的 shell 的语法,例如作为 bashcmd.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆