Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如果是,则对deb文件执行命令_Ios_Bash_If Statement - Fatal编程技术网

Ios 如果是,则对deb文件执行命令

Ios 如果是,则对deb文件执行命令,ios,bash,if-statement,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/AppleColorEm

我想为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

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

您需要在if语句中使用-f标志。-f标志测试文件,请参阅
man test
,了解所有可能的情况

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

#!/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

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

#!/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

和林寻是你的朋友。它是
preinst
而不是
presint
preints
。你真的想在你的iPhone/iOS设备上执行吗?是越狱吗?如果不是越狱,你就不能那样做。。我想在我的iPhone/iOS设备上执行。。是的,我的iphone被越狱了。。很抱歉我的打字错误。。我正在使用preinst..你能做一个
chmod 777/System/Library/font/Cache
吗?首先查看并在某处写下ls-l/System/Library/font/Cache的原始权限。
mv/System/Library/font/Cache/AppleColorEmoji.ttf/System/Library/font/Cache/AppleColorEmoji.backup运行时,目录和文件名正确。尝试在开始时回显“Hello there”
,在第一个if语句之前回显
ls${orgdir}
。你的脚本有执行权限吗?当你启动它时,它会说什么?您是否看到mv命令中的“无法备份字体”或错误消息?您好,Walter A。。我已经在尝试
echo“Hello There”
ls-l/System/Library/font/Cache
了,但是没有任何变化。。我看不到'echo“Hello There”和“cannot backup font”,mv命令也没有错误消息..:(因此,脚本似乎根本没有执行。请尝试
chmod 777 yourscript
,并检查第一行的最后一个字符是否为
h
(而不是空格、制表符或^M)。