if,然后命令deb文件

时间:2015-05-12 07:00:29

标签: ios bash if-statement

我想为iOS创建一个deb文件。我在debian文件夹上创建了3个命令文件,它的presint,postint和postrm。为什么在安装deb文件时此代码无法正常工作?

#!/bin/bash

if [ "/System/Library/Fonts/Cache/AppleColorEmoji.ttf" ];then
mv /System/Library/Fonts/Cache/AppleColorEmoji.ttf /System/Library/Fonts/Cache/AppleColorEmoji.backup

elif [ "/System/Library/Fonts/Cache/AppleColorEmoji@2x.ttf" ];then
mv /System/Library/Fonts/Cache/AppleColorEmoji@2x.ttf /System/Library/Fonts/Cache/AppleColorEmoji@2x.backup

elif [ "/System/Library/Fonts/Cache/AppleColorEmoji@3x.ttf" ];then
mv /System/Library/Fonts/Cache/AppleColorEmoji@3x.ttf /System/Library/Fonts/Cache/AppleColorEmoji@3x.backup

else
     echo "cannot backup font"
fi

我希望此命令能够找到目录中的文件并将该文件重新保存到备份中。

2 个答案:

答案 0 :(得分:1)

if语句中需要-f标志。 -f标志测试文件,有关所有可能性,请参阅man test

我还添加了一些var以使代码更易于阅读:

#!/bin/bash
orgdir="/System/Library/Fonts/Cache"
# targetdir is here equal to orgdir, maybe you want to change in the future.
targetdir="/System/Library/Fonts/Cache"

# When orgdir or targetdir contains spaces, you need double quotes,
# in this example you do not need them.
# I use the double quotes for good habits

if [ -f "${orgdir}/AppleColorEmoji.ttf" ]; then
   mv "${orgdir}/AppleColorEmoji.ttf" "${targetdir}/AppleColorEmoji.backup"
elif [ -f "${orgdir}/AppleColorEmoji@2x.ttf" ]; then
   mv "${orgdir}/AppleColorEmoji@2x.ttf" "${targetdir}/AppleColorEmoji@2x.backup"
elif [ -f "${orgdir}/AppleColorEmoji@3x.ttf" ]; then
   mv "${orgdir}/AppleColorEmoji@3x.ttf" "${targetdir}/AppleColorEmoji@3x.backup"   
else
     echo "cannot backup font"
fi

答案 1 :(得分:0)

我的问题解决..我使用这个脚本..

#!/bin/bash
cd /System/Library/Font/Cache

Em="AppleColorEmoji.ttf"
Em2="AppleColorEmoji.Backup"

if [ -f "${Em}" ]; then
   mv "${Em}" "${Em2}"
else echo "Searching.."
fi

Em3="AppleColorEmoji@2x.ttf"
Em4="AppleColorEmoji@2x.Backup"

if [ -f "${Em3}" ]; then
  mv "${Em3}" "${Em4}"
else echo "Searching.."
fi

Em5="AppleColorEmoji@3x.ttf"
Em6="AppleColorEmoji@3x.Backup"

if [ -f "${Em5}" ]; then
  mv "${Em5}" "${Em6}"
else echo "Searching.."
fi