【问题标题】:Bash timestamp comparisionsBash 时间戳比较
【发布时间】:2009-08-10 14:45:45
【问题描述】:

我对 Bash 脚本完全陌生,但有人告诉我,在没有什么帮助的情况下,只有在文件自上次运行脚本后已被修改时,才创建一个将纹理压缩为 PVR 格式的文件。这是我到目前为止的代码:


# variables
TEXTURE_TOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool
INPUT_DIR="/Data/Mobile"
OUTPUT_DIR="/Data/iPhone"
IMAGE_GREP="\(.bmp\|.png\)"
OTHER_GREP="\.b3d$"

echo "Starting backup of directory $INPUT_DIR to directory $OUTPUT_DIR"

# cycle through the input directory for images we can compress
echo "Compressing textures!"
for i in $( ls -a "$INPUT_DIR" | grep $IMAGE_GREP  ); 
     do
        if test "$OUTPUT_DIR/$i.pvr" -nt "$INPUT_DIR/$i"; then
        # check to see output's status
        echo "Compressing file $i!"

        # compress and store in output directory
        $TEXTURE_TOOL -m -e PVRTC --bits-per-pixel-2 -o "$OUTPUT_DIR/$i.pvr" -f PVR "$INPUT_DIR/$i"
        fi
     done

# cycle through the input directory for models we can export
echo "Moving models!"
for i in $( ls -a "$INPUT_DIR" | grep $OTHER_GREP  ); 
     do
        # check to see output's status
        echo "Moving model file $i!"

        # cp to output directory
        cp "$INPUT_DIR/$i" "$OUTPUT_DIR/$i"
     done

使用此处的一个问题,我尝试进行时间戳检查,但它不起作用,我很确定它是因为我不完全理解代码。

谁能建议我做错了什么

谢谢,迈克尔 A

【问题讨论】:

    标签: macos bash unix timestamp


    【解决方案1】:

    使用make 可以最好地实现仅在某些文件比预期新的情况下执行操作。这学习起来有点复杂,但非常有效。

    【讨论】:

    • +1。 正确地学习可能会更复杂,但是对于像 OP 这样相对简单的任务,只需使用现有的 makefile 就可以很快解决。所以对于 OP,不要被复杂性的警告所推迟;确实值得努力。
    【解决方案2】:
    test "$OUTPUT_DIR/$i.pvr" -nt "$INPUT_DIR/$i";
    

    检查 $OUTPUTDIR/$i.pvr 是否比 $INPUTDIR/$i 更新,我想你想反过来做。

    test "$INPUT_DIR/$i" -nt "$OUTPUT_DIR/$i.pvr";
    

    检查输入是否比输出新。

    【讨论】:

      猜你喜欢
      • 2012-07-09
      • 1970-01-01
      • 2016-07-26
      • 2011-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      相关资源
      最近更新 更多