为什么我的脚本在使用 /../ 时没有上升一级?

发布于 2024-10-09 17:27:32 字数 725 浏览 0 评论 0原文

我知道在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断舍离 2024-10-16 17:27:32

/ 表示从文件系统或上下文的根开始,../ 表示向上一级。 /../ 有效地取消了两者。

要上升一级,请尝试 ../

编辑:换句话说,尝试从路径中变量的末尾删除 / 。

编辑#2:最好的解决方案可能只是删除 /../

编辑#3:

这会起作用:

  /var/mobile/Applications/1E17CC78-AA6E-4FFA-B241-74A73FE3AB0E/CutTheRope.app/Library/../Library/Preferences/

如果您删除了第二个库和 .. 它也应该起作用:

 /var/mobile/Applications/1E17CC78-AA6E-4FFA-B241-74A73FE3AB0E/CutTheRope.app/Library/Preferences/

/ 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:

  /var/mobile/Applications/1E17CC78-AA6E-4FFA-B241-74A73FE3AB0E/CutTheRope.app/Library/../Library/Preferences/

And if you removed the second Library and the .. it should also work:

 /var/mobile/Applications/1E17CC78-AA6E-4FFA-B241-74A73FE3AB0E/CutTheRope.app/Library/Preferences/
苹果你个爱泡泡 2024-10-16 17:27:32

查找过程如下:

inode lookup(string path) {
  inode cur = path[0] == '/' ? process->root_directory : process->current_directory;
  foreach component in split(path, '/') {
    inode next = cur.get_entry(component);
    if (next is a file && the component is the last one)
      return;
    if (next is a directory)
      cur = next;
    else
      return null;
  }
  return cur;
}

对于..没有特殊处理。关键是文件只能显示为路径的最后一个组成部分。如果它出现在之前,则将采用 return null 路径。

实际实现(例如 NetBSD)有点复杂。

更新:我刚刚看到在你的问题中$appdir可能会指向一个目录,所以上面的讨论不适用。尽管如此,可能还涉及一些符号链接。当您跟随符号链接然后继续使用 .. 时,lookup 函数将从符号链接指向的位置继续。一个小例子:

$ ln -s somewhere/else/deep/in/the/path symlink
$ ls -l symlink/..

这将解析为 somewhere/else/deep/in/the (只要它存在)。 lookup 函数不会将路径 symlink/.. 简化为 . 或作为另一个示例 first/../second 不会简化为 second

The lookup procedure is as follows:

inode lookup(string path) {
  inode cur = path[0] == '/' ? process->root_directory : process->current_directory;
  foreach component in split(path, '/') {
    inode next = cur.get_entry(component);
    if (next is a file && the component is the last one)
      return;
    if (next is a directory)
      cur = next;
    else
      return null;
  }
  return cur;
}

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, the return 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 .., the lookup function continues from where the symlink points to. A small example:

$ ln -s somewhere/else/deep/in/the/path symlink
$ ls -l symlink/..

This will resolve to somewhere/else/deep/in/the (provided it exists). The lookup function will not simplify the path symlink/.. to . or as another example first/../second will not be simplified to second.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文