-2

I am creating a directory using the following command in Unix. This line is a part of a shell script which I am trying to run.

mkdir ./R

And it makes a dir named R? What does this mean?

trougc
  • 329
  • 3
  • 14
  • What leads you to believe that's the directory it's created? Does `stat R?` succeed yet `stat R` does not? – dimo414 Jun 04 '18 at 21:26

2 Answers2

2

Assuming you're using ls to see this ? symbol, man ls notes that the --hide-control-chars will insert ? symbols where a filename has non-graphic characters. Assuming this flag is set (e.g. if you have an alias alias ls=ls -q) It's possible your mkdir command has an additional non-printing character after the R (e.g. if you copy-pasted the line from somewhere).

dimo414
  • 47,227
  • 18
  • 148
  • 244
  • Some versions of `ls` behave this way by default. `man ls` to find options to change the way file names are displayed. Or use filename completion to change the name: `mv R R` (if the directory is the only thing in the current directory whose name starts with `R`, this will let you rename it -- and what the tab expansion shows could be informative). Your answer assumes the GNU coreutils version of `ls`; since the OP only said Unix, that's not a safe assumption. – Keith Thompson Jun 04 '18 at 21:41
1

Your shell script has DOS line endings. The shell sees the command as mkdir ./R^M where ^M is a carriage return. You can confirm this with cat -v.

$ cat -v script
mkdir ./R^M

ls will print control characters with question marks ?. Printing them directly would mess up its output.

To fix the file convert it from DOS to UNIX format.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578