【问题标题】:Space in a folder, terminal can't cd文件夹中的空间,终端无法cd
【发布时间】:2018-01-31 04:55:56
【问题描述】:

Macbook Pro 13" 2016,High Sierra 10.13.2

我知道终端无法打开/cd 带有空格的文件夹,除非存在符号 \" " 围绕空格或整个文件夹名称。但是,终端和 iTerm 仍然存在问题。

*****:~ #######$ cd /Users/#######Google\ Drive -bash: cd: /Users/#######/Google: No such file or directory *****:~ #######$ cd Google\ Drive/ -bash: cd: Google: No such file or directory *****:~ #######$ cd Google' 'Drive/ -bash: cd: Google: No such file or directory *****:~ #######$ cd 'Google Drive'/ -bash: cd: Google: No such file or directory *****:~ #######$ cd "Google Drive" -bash: cd: Google: No such file or directory *****:~ #######$ cd Google" "Drive -bash: cd: Google: No such file or directory

通过 ls 可以看到 Google 云端硬盘。

Google 云端硬盘也可以自动完成输入(输入 Goo 并按回车键)并将文件夹从 Finder 拖放到终端,其中终端插入 \ 本身并为您提供 Google\ Drive/

此行为可能与我 Mac 上的所有文件夹有关。这已经发生了一段时间,我想解决它。

附:问题主要出现在cd 命令上。

更新。

根据要求,这是 stivens ~ $ ls -d Google*Drive | xxd 00000000: 476f 6f67 6c65 2044 7269 7665 0a 谷歌驱动器。

type cd

stivens ~ $ type cd
cd is a function
cd ()
{
    unset RETVAL;
    if __gvm_is_function __gvm_oldcd; then
        __gvm_oldcd $*;
    fi;
    local dot_go_version dot_go_pkgset rslt;
    local defaults_go_name defaults_go_pkgset;
    local defaults_resolved=false;
    local defaults_hash;
    defaults_hash=();
    if [[ "$GVM_ROOT" == "" ]]; then
        __gvm_display_error "GVM_ROOT not set. Please source \$GVM_ROOT/scripts/gvm";
        return $?;
    fi;
    [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving defaults...";
    __gvm_read_environment_file "${GVM_ROOT}/environments/default" > /dev/null;
    rslt=$?;
    defaults_hash=(${RETVAL});
    if [[ $rslt -eq 0 ]]; then
        defaults_resolved=true;
    else
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find default environment. Falling back to system.";
        __gvm_read_environment_file "${GVM_ROOT}/environments/system" > /dev/null;
        rslt=$?;
        defaults_hash=(${RETVAL});
        if [[ $rslt -eq 0 ]]; then
            defaults_resolved=true;
        else
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find system environment.";
        fi;
    fi;
    if [[ "${defaults_resolved}" == false ]]; then
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving fallback go version and pkgset from all available.";
        local fallback_go_version="";
        __gvm_resolve_fallback_version > /dev/null;
        fallback_go_version="${RETVAL}";
        local fallback_go_pkgset="";
        __gvm_resolve_fallback_pkgset "${fallback_go_version}" > /dev/null;
        fallback_go_pkgset="${RETVAL}";
        {
            setValueForKeyFakeAssocArray "gvm_go_name" "${fallback_go_version}" "${defaults_hash[*]}" > /dev/null;
            defaults_hash=(${RETVAL});
            setValueForKeyFakeAssocArray "gvm_pkgset_name" "${fallback_go_pkgset}" "${defaults_hash[*]}" > /dev/null;
            defaults_hash=(${RETVAL})
        };
        unset fallback_go_version;
        unset fallback_go_pkgset;
        defaults_resolved=true;
    fi;
    defaults_go_name="";
    defaults_go_pkgset="";
    {
        valueForKeyFakeAssocArray "gvm_go_name" "${defaults_hash[*]}" > /dev/null;
        defaults_go_name="${RETVAL}";
        valueForKeyFakeAssocArray "gvm_pkgset_name" "${defaults_hash[*]}" > /dev/null;
        defaults_go_pkgset="${RETVAL}"
    };
    if [[ "${GVM_DEBUG}" -eq 1 ]]; then
        echo "Resolved default go: ${defaults_go_name:-[EMPTY]}";
        echo "Resolved default pkgset: ${defaults_go_pkgset:-[EMPTY]}";
    fi;
    __gvmp_find_closest_dot_go_version > /dev/null;
    rslt=$?;
    dot_go_version="${RETVAL}";
    if [[ $rslt -eq 0 ]]; then
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found dot_go_version: ${dot_go_version}";
        local use_goversion="";
        __gvmp_read_dot_go_version "${dot_go_version}" > /dev/null;
        use_goversion="${RETVAL}";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_goversion}";
        \gvm use --quiet "${use_goversion}" || return 1;
        unset use_goversion;
    else
        if [[ -n "${defaults_go_name}" ]]; then
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-version found. Using system or default go.";
            \gvm use --quiet "${defaults_go_name}" || return 1;
        else
            if [[ "${GVM_DEBUG}" -eq 1 ]]; then
                local installed_hash;
                installed_hash=();
                __gvm_find_installed "" "${GVM_ROOT}/gos" > /dev/null;
                installed_hash=(${RETVAL});
                local go_archive_path="$GVM_ROOT/archive/go";
                echo "No fallback go version could be found.";
                if [[ ${#installed_hash[@]} -eq 0 && ! -d "${go_archive_path}" ]]; then
                    __gvm_locale_text_for_key "go_install_prompt" > /dev/null;
                    __gvm_display_error "${RETVAL}";
                    return 1;
                fi;
                unset go_archive_path;
                unset installed_hash;
            fi;
            return 0;
        fi;
    fi;
    __gvmp_find_closest_dot_go_pkgset > /dev/null;
    rslt=$?;
    dot_go_pkgset="${RETVAL}";
    if [[ $rslt -eq 0 ]]; then
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found .go-pkgset: ${dot_go_pkgset}";
        local use_gopkgset="";
        __gvmp_read_dot_go_pkgset "${dot_go_pkgset}" > /dev/null;
        use_gopkgset="${RETVAL}";
        [[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_gopkgset}";
        \gvm pkgset use --quiet "${use_gopkgset}" || return 1;
        unset use_gopkgset;
    else
        if [[ -n "${defaults_go_pkgset}" ]]; then
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-pkgset found. Using system or default pkgset.";
            \gvm pkgset use --quiet "${defaults_go_pkgset}" || return 1;
        else
            [[ "${GVM_DEBUG}" -eq 1 ]] && echo "No fallback pkgset could be found.";
        fi;
    fi;
    return 0
}

command cd Google\ Drive/ 有效,\cd Google\ Drive/ 无效。

【问题讨论】:

  • 运行type cd 看看它说了什么。听起来你为它添加了一个有问题的自定义函数
  • 我同意前面的评论;症状肯定看起来像你有一个不标准的cd。您另外可能有一个空格字符,它实际上不是文件夹名称中的常规 ASCII 空格。查看ls -d Google*Drive | xxd 是否显示任何异常(常规空格是十六进制的20,而其他一些Unicode 空格可能是跨越多个字节的复杂事物,或者可能是一个控制字符)。
  • 您可以使用command cd Google\ Drive/\cd Google\ Drive/ 临时覆盖越野车cd
  • 一方面,__gvm_oldcd $* 应该是 __gvm_oldcd "$@"
  • 如何将__gvm_oldcd $* 更改为__gvm_oldcd "$@"?以及一般如何修复cd?什么可能导致了这个问题?

标签: bash terminal macbookpro-touch-bar


【解决方案1】:

好的,我找到了导致问题的原因。

我注意到type cd 中出现了GVM,并回忆起在某个时候我安装了Go Version Manager,又名GVM,并在.bash_profile [[ -s "/Users/stivens/.gvm/scripts/gvm" ]] && source "/Users/stivens/.gvm/scripts/gvm" 中找到了一个脚本解析器。

我刚刚将其注释掉,现在cd 可以正常工作。

巴津加!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 2023-03-14
    相关资源
    最近更新 更多