我想为iOS创建一个DEB文件。我在Debian文件夹上创建了3个命令文件,其PROSINT,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
我希望此命令能够在dir中找到什么文件,并将该文件删除为备份。
您需要if -statement中的-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
我的problm solve ..我使用此脚本..
#!/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