【发布时间】:2017-02-01 19:29:29
【问题描述】:
在我开始之前,请不要咬我的头,我知道这个问题在这里和其他论坛已经被问过很多次了,但是我无法让这个简单的 shell 脚本工作。
这是我的脚本:
#!/bin/bash
DEST=“/Volumes/Ext\ 1TB/Google\ Drive/Backup\ Ralph/mac”
echo dest is $DEST
cd $DEST
这是我的输出:
bash -x gdrive.sh
+ DEST='“/Volumes/Ext 1TB/Google Drive/Backup Ralph/mac”'
+ echo dest is $'?\200\234/Volumes/Ext' 1TB/Google Drive/Backup $'Ralph/mac?\200\235'
dest is “/Volumes/Ext 1TB/Google Drive/Backup Ralph/mac”
+ cd $'?\200\234/Volumes/Ext' 1TB/Google Drive/Backup $'Ralph/mac?\200\235'
gdrive.sh: line 6: cd: “/Volumes/Ext: No such file or directory
我尝试了很多组合,比如单引号或双引号,或者用反斜杠转义,或者用双引号和反斜杠转义
如果我在变量周围加上双引号,输出会给我一些数字,如您在我的示例中看到的那样。
有人知道转义引号的正确用法和组合是什么吗?
希望有人能帮忙
问候,
拉尔夫
【问题讨论】:
-
双引号不是普通的双引号,而是特殊字符。这里是固定的:
"/Volumes/Ext\ 1TB/Google\ Drive/Backup\ Ralph/mac"。顺便说一句,您不需要使用 \ 转义嵌入的空格,这也可以正常工作:"/Volumes/Ext 1TB/Google Drive/Backup Ralph/mac"