目录路径变量是否应该以斜杠结尾? [英] Should a directory path variable end with a trailing slash?
问题描述
在将目录的路径定义为变量或常量时,它应该以斜杠结尾吗?约定是什么?
When defining a path to a directory as a variable or constant, should it end with a trailing slash? What is the convention?
pwd
显示的是当前目录,没有后加斜杠,而cd /var/www/apps/
的制表符完整包含后跟斜杠,这让我不确定.
pwd
in Unix shows your current directory without a trailing slash, while the tab complete of cd /var/www/apps/
includes the trailing slash, which left me unsure.
推荐答案
例如,当我定义用于存储文件的目录时,我不包括斜杠.那是因为我会像这样使用它
I don't include the trailing slash when I, for example, define a directory for storing files. That is because I will use it like
$store_file = "$store_path/$file_id";
在使用应该包含目录路径的变量之前,我总是会在末尾添加斜杠.我认为总要添加一个总比不知道是否包含结尾的斜杠好.
I will always add a trailing slash before using a variable that's supposed to hold a directory path. I think it's better to always add one than to wonder if the trailing slash is included.
这篇关于目录路径变量是否应该以斜杠结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!