【发布时间】:2020-08-26 03:43:17
【问题描述】:
我的路径很长 /mnt/ABC/user/user123/domain1/computer1/My Document/ 里面有多个目录。我试图输入完整路径,并考虑在 .profile 中设置一个环境变量来缩短它,但无论如何都失败了。请帮忙。
attempt 1:
adm@linux-lygy:~> export XYZS=/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software
adm@linux-lygy:~> echo $XYZS/DB
/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ/DB
attempt 2:
adm@linux-lygy:~> export XYZS="/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software"
adm@linux-lygy:~> echo $XYZS/DB
/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software/DB
adm@linux-lygy:~> ls $XYZS/DB
ls: cannot access '/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ': No such file or directory
ls: cannot access 'Software/DB': No such file or directory
attempt 3:
adm@linux-lygy:~> export XYZS="/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\ Software"
adm@linux-lygy:~> echo $XYZS/DB
/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software/DB
adm@linux-lygy:~> echo $XYZS/DB
/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\ Software/DB
adm@linux-lygy:~> ls $XYZS/DB
ls: cannot access '/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\': No such file or directory
ls: cannot access 'Software/DB': No such file or directory
attempt 4:
adm@linux-lygy:~> export XYZS="\"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software\""
adm@linux-lygy:~> echo $XYZS/DB
"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software"/DB
adm@linux-lygy:~> ls $XYZS/DB
ls: cannot access '"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ': No such file or directory
ls: cannot access 'Software"/DB': No such file or directory
adm@linux-lygy:~> echo "$XYZS"/DB
"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software"/DB
adm@linux-lygy:~> ls "$XYZS"/DB
ls: cannot access '"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ Software"/DB': No such file or directory
attempt 5:
adm@linux-lygy:~> export XYZS="\"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\ Software\""
adm@linux-lygy:~> echo $XYZS/DB
"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\ Software"/DB
adm@linux-lygy:~> ls $XYZS/DB
ls: cannot access '"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\': No such file or directory
ls: cannot access 'Software"/DB': No such file or directory
adm@linux-lygy:~> echo "$XYZS"/DB
"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\ Software"/DB
adm@linux-lygy:~> ls "$XYZS"/DB
ls: cannot access '"/mnt/ABC/user/user123/domain1/computer1/Personal/XYZ\ Software"/DB': No such file or directory
【问题讨论】:
-
“我试图输入完整路径”——你的意思是“我厌倦了输入完整路径”?无论如何,请阅读 shell 的说明。例如,对于 Bash,
control-R允许您对历史记录进行反向搜索。在任何情况下,如果您有空格,则必须使用引号来防止 shell 在该空格处将命令行拆分为两个参数。
标签: bash unix environment-variables