PHP Learner
PHP Learner

Reputation: 741

Same commands, different results

I saw a weird behavior in my bash terminal. I run same commands on my terminal command line, but get different results. Following lines are copied-pasted from my bash terminal windows:

me@me:~$ ls "/media/me/My Passport/Archive U/‌"
ls: cannot access /media/me/My Passport/Archive U/‌: No such file or directory
me@me:~$ ls "/media/me/My Passport/Archive U/‌"
Backup  Documents  Downloads  Music  Pictures  Videos

I tried both commands using up arrow key (to bring previous commands to the current line) many times and the result does not changes. To be sure that the command has no hidden character, I selected both commands and pasted it to an spreed sheet and converted each character to its code and compared. there was no difference. I tried to select each commands and right-click, choose Copy, right click again, choose paste. If I copy-paste first command, I get first result. I f I copy-paste second command, I get second result!!!

Could any one say what is the difference between two commands? I guess no one could!

I tell you what is the difference. First command is copied and pasted from a text file!

I am using Ubuntu 14.04.

** Update to be sure about my copy past process ** following lines are copied and pasted directly from history output of terminal window:

 2602  [2015-05-09 07:25:20] ls "/media/me/My Passport/Archive U/‌"
 2603  [2015-05-09 07:25:54] ls /media/me/My\ Passport/Archive\ U/
 2604  [2015-05-09 07:26:02] ls "/media/me/My\ Passport/Archive\ U/"
 2605  [2015-05-09 07:26:10] ls "/media/me/My Passport/Archive U/"
 2606  [2015-05-09 07:27:05] ls "/media/me/My Passport/Archive U/‌"
 2607  [2015-05-09 07:28:26] ls "/media/me/My Passport/Archive U/"
 2608  [2015-05-09 07:56:19] ls /media/me/My\ Passport/Archive\ U/‌
 2609  [2015-05-09 07:57:06] ls "/media/me/My Passport/Archive U/"
 2610  [2015-05-09 07:57:15] ls "/media/me/My Passport/Archive U/‌"

Upvotes: 1

Views: 384

Answers (1)

chepner
chepner

Reputation: 532238

I copied the code from your question into vim, and see this:

me@me:~$ ls "/media/me/My Passport/Archive U/<200c>"
ls: cannot access /media/me/My Passport/Archive U/<200c>: No such file or directory
me@me:~$ ls "/media/me/My Passport/Archive U/<200c>"
Backup  Documents  Downloads  Music  Pictures  Videos

U+200c is the zero-width non-joiner, an invisible character. I suspect you copied and pasted the first, failing command twice when creating the question. The two commands you are running are, indeed different; the first command includes a character you copied from its source, while you would not have typed the character in the second case.

Upvotes: 2

Related Questions