进行本地复制时是否有可能使 scp 失败?

Jas*_*son 7 shell scp

进行scp本地复制时是否可能失败?我发现不小心创建名称的文件很烦人,例如192.168.11.5我打算键入时192.168.11.5:将文件复制到远程计算机。

小智 6

默认情况下不是,但如果你想要一些快速的东西,你可以在它周围创建一个包装器,比如将原始二进制文件移动到 scp.orig 并有一个新的 shell 脚本来接受输入,检查输入中是否有 : 并传递它,如果没有提示继续?

编辑:这篇文章回答了我的问题,所以我接受了,但我想添加我编写的可以为我解决问题的 shell 函数:

# Simple wrapper around scp to avoid forgotten colon's
scp() {
    if [[ $@ == *:* ]]; then
        # Looks like a valid command so run it
        command scp "$@"
    else
        echo -n "Would you like to add a colon to the end of the function? [y/n] "
        read response
        if [ "$response" = "y" ]; then
            command scp "$@":
        else
            command scp "$@"
        fi
    fi
}
Run Code Online (Sandbox Code Playgroud)