gpt4 book ai didi

linux - 如何将带有空格的绝对文件路径传递给 linux shell 脚本?

转载 作者:太空宇宙 更新时间:2023-11-04 09:28:35 26 4
gpt4 key购买 nike

<分区>

我想使用 linux shell 脚本自动进行视频转换。我在 ubuntu 14.04 上使用 HandBrakeCLI 和我的个人选项。但我被困在某个时刻。这是我想用伪代码完成的:

# watch a specific folder (A)
- if a (source) file is older then 1d process it
- as soon as the process is finished move the source file into folder (B)
- the target for the new file is folder (C)
# process the files
1. find all the new files (older then 1d) within (A)
2. get the full path of the file and store it
3. replace the source folder path (A) with the target folder (C)
4. start conversion with HandBrakeCLI like:
HandBrake $options $sourcefile $targetfile

我用这段代码介绍了特定文件夹扫描的第一部分:

find $A -name "*.mkv" -ctime +1 -print0

我想将源文件的绝对路径从文件夹 (A) 传递到我的脚本“convertMkv”中。棘手的部分就在这里:

find $A -name "*.mkv" -ctime +1 -print0 | xargs -0 -I {} ./convertMkv "{}" "$C" ;

我想将源文件从文件夹 (A) 和目标文件夹 (C) 传递到我的转换脚本,它将准备必要的路径并触发 HandBrakeCLI。

源文件的路径示例可以是:

"/tmp/Video of Interest.mkv"

"/tmp/File\ Folder/Lion_King.mkv"

"/tmp/Avatar.mkv"


这是我的“convertMkv”脚本:

#!/bin/bash
source="$HOME/handbrake/.raw"
target="$2"

OPT=""
OPT="$OPT --verbose"
OPT="$OPT --encode x264"
OPT="$OPT --quality 20.0"
OPT="$OPT --format mp4"
...

# -----------------------------------------------------------------------------
# mkv2mp4()
# -----------------------------------------------------------------------------
function mkv2mp4
{
input=$1
output=$2

HandBrakeCLI $OPT -i "$input" -o "$output" 2>&1 | tee "/tmp/log/Test.log"
}

function main
{
path="${1%/*}"
file="${1##*/}"
newPath="${path##/*/}"

mkv2mp4 $1 $target/$newPath/$file
}

main $@
exit 0

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com