为什么我的脚本在使用 /../ 时没有上升一级?
我知道在 bash 的文件位置使用“/../”会上升一级。这就是我在这里尝试做的:
for box in {0..4}
do
for lvl in {0..24}
do
key="UNLOCKED_${box}_$lvl"
plutil -key "$key" -value '1' "$appdir/../Library/Preferences/com.chillingo.cuttherope.plist" 2>&1> /dev/null
#successCheck=$(plutil -key "$key" "/$appdir/../Library/Preferences/com.chillingo.cuttherope.plist")
#if [ "$successCheck" -lt 1 ]; then
# echo "Level ${box}-$lvl failed! "
#fi
done
done
但我不断收到此错误(x125):
Error: File not found at path /var/mobile/Applications/1E17CC78-AA6E-4FFA-B241-74A73FE3AB0E/CutTheRope.app/../Library/Preferences/com.chillingo.cuttherope.plist
任何帮助将不胜感激/ 谢谢。
I have the understanding that using "/../" in a file location in bash will go up one level. That's what I'm trying to do here:
for box in {0..4}
do
for lvl in {0..24}
do
key="UNLOCKED_${box}_$lvl"
plutil -key "$key" -value '1' "$appdir/../Library/Preferences/com.chillingo.cuttherope.plist" 2>&1> /dev/null
#successCheck=$(plutil -key "$key" "/$appdir/../Library/Preferences/com.chillingo.cuttherope.plist")
#if [ "$successCheck" -lt 1 ]; then
# echo "Level ${box}-$lvl failed! "
#fi
done
done
But I keep getting this error (x125):
Error: File not found at path /var/mobile/Applications/1E17CC78-AA6E-4FFA-B241-74A73FE3AB0E/CutTheRope.app/../Library/Preferences/com.chillingo.cuttherope.plist
Any help would be greatly appreciated/
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
/ 表示从文件系统或上下文的根开始,../ 表示向上一级。 /../ 有效地取消了两者。
要上升一级,请尝试 ../
编辑:换句话说,尝试从路径中变量的末尾删除 / 。
编辑#2:最好的解决方案可能只是删除 /../
编辑#3:
这会起作用:
如果您删除了第二个库和 .. 它也应该起作用:
/ means start from the root of the filesystem or context, and ../ means go up one level. /../ effectively cancels the two out.
To go up one level, try ../
EDIT: In other words, try removing the / from the end of the variable in your path.
EDIT #2: The best solution is to probably just remove the /../
EDIT #3:
This would work:
And if you removed the second Library and the .. it should also work:
查找过程如下:
对于
..
没有特殊处理。关键是文件只能显示为路径的最后一个组成部分。如果它出现在之前,则将采用return null
路径。实际实现(例如 NetBSD)有点复杂。
更新:我刚刚看到在你的问题中
$appdir
可能会指向一个目录,所以上面的讨论不适用。尽管如此,可能还涉及一些符号链接。当您跟随符号链接然后继续使用..
时,lookup
函数将从符号链接指向的位置继续。一个小例子:这将解析为
somewhere/else/deep/in/the
(只要它存在)。lookup
函数不会将路径symlink/..
简化为.
或作为另一个示例first/../second 不会简化为
second
。The lookup procedure is as follows:
There is no special handling for
..
. The point is that a file can only appear as the very last component of the path. If it appears before, thereturn null
path will be taken.The actual implementation (for example in NetBSD) is a bit more complicated.
Update: I just saw that in your question
$appdir
will probably point to a directory, so the above discussion does not apply. Still, there might be some symlinks involved. When you follow a symlink and then continue with..
, thelookup
function continues from where the symlink points to. A small example:This will resolve to
somewhere/else/deep/in/the
(provided it exists). Thelookup
function will not simplify the pathsymlink/..
to.
or as another examplefirst/../second
will not be simplified tosecond
.