为什么我的脚本在使用/../时没有达到一个级别?

时间:2011-01-02 21:06:29

标签: bash scripting path

我理解在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

任何帮助将不胜感激/ 感谢。

2 个答案:

答案 0 :(得分:1)

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

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

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

编辑#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/

答案 1 :(得分:0)

查找程序如下:

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