That would likely be a "display" thing with
ls, i.e., if you do
ls -p or
ls -F, it should consistently add the slash after directories. It's essentially adding visual cues as to what it thinks the file is. (Do note that
-F will also, e.g., append
@ to symlinks,
* to files with executable permissions,
| to named pipes,
= to sockets and so on). You can also reproduce with
ls -d directory/ vs
ls -d directory.
\0 I believe is the only two characters not valid in a file/directory name.
Always adding the slash should be safe, if you've assigned mydirectory and myfile correctly, doing
vim "$mydirectory/$myfile" should do what you expect. (With the caveat of
$myfile having been assigned correctly).
foo//bar should be equivalent.
Generally; I really dislike assigning the output of ls to variables and dealing with it, primarily because I've previously been surprised about characters ending up into filenames combined with lacking quoting, ending up with destructive results. (I.e.
prefix=/home user=" oops" rm -rf $prefix$user, which would end up recursively deleting
/home, and then trying to recursively delete
Instead of using ls, I try when I can to rely on glob expansion by bash, or
find -print0 | xargs -0. If you do use
ls, ensure you're NOT using an existing alias for
ls, and you use the display options that fits your particular task.