小编Mar*_*eth的帖子

scp 过早解释波浪号 (~) 的 Bash 脚本

所以,我刚刚开始了一个新的 C++ 类,它要求我在 Linux 环境中进行编程。我的机器上没有安装 Linux,但我有 OS X,我可以在学校实验室的 linux 机器上使用 ssh(这是可取的,因为我的代码必须在实验室机器上编译和运行,无论是否不适用于我的机器)。如果你在这个问题的结尾还说不清楚,我对 Linux 并不是非常熟悉。

我经常需要将我下载到本地机器上的文件放在远程机器上,编辑它们以制作程序,然后将它们放回我的本地机器上以将它们上传到我们的保管箱。我厌倦了打字
scp -P xx user@remote.host.com:~/filename filename
,决定做一个别名来做到这一点。那时我发现别名不能处理这种事情,所以我决定写一个 shell 脚本来代替。这是我所拥有的:

#!/bin/bash

# Author: me
# Created 26 August 2014
# transfers a file from remote machine to current directory in local machine
# keeps same filename

location="$1"
# name gets just the part of the path after the last slash
# ie the filename
name="$(echo "$1" | sed -n -e 's/^.*\///p')"
# echo "$location"
# echo "$name"
scp …
Run Code Online (Sandbox Code Playgroud)

bash scp shell-script quoting home

4
推荐指数
1
解决办法
2887
查看次数

标签 统计

bash ×1

home ×1

quoting ×1

scp ×1

shell-script ×1