0

I read a previous question... found here: Windows equivalent to UNIX pwd

Unfortunately, when I tried to do the same thing as what the person mentioned below (except for ls.cmd and @echo %dir%), it only displayed the words "ECHO is on." in the command line. I did the same exact thing for pwd and it worked, but how come this doesn't work? Thanks.

Open notepad as administrator and write:

@echo %cd%

Save it in c:\windows\system32\ with the name "pwd.cmd" (be careful not to > save pwd.cmd.txt)

Then you have the pwd command.

EDIT: Maybe I should rephrase. I'm basically trying to create my own Windows command of the UNIX command "ls," which lists directories (the same as Windows' "dir" command). This is strictly for learning purposes as I could just as easily type dir as ls, but I wanted to see why this doesn't work.

Community
  • 1
  • 1
Freedom
  • 347
  • 2
  • 7
  • 24

2 Answers2

3
@echo %dir%

will call echo without arguments, hence the "echo is on" message.

It does not work that way. %cd% contains current directory, it is a special env. variable. dir, on the other hand is a command which has no env. variable counterpart (what would it contain?)

You have to replace the line above by just dir /B to call the command. Output looks a lot like ls.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
1

I can see that the cd command on Windows, if given no arguments, shows the current directory (instead of changing to the home directory like on Linux).

So try to write "cd" itself in there. Echoing a variable may or may not work well.

NOTE: I answered a different question and I want to be notified when the question is updated to be proper. The thing is that this question originally did not have any code to fix, and thus lacked the minimal, verifiable, complete example.

Paul Stelian
  • 1,381
  • 9
  • 27
  • Maybe I should rephrase. I'm basically trying to create my own Windows command of the UNIX command "ls," which lists directories (the same as Windows' "dir" command). This is strictly for learning purposes as I could just as easily type dir as ls, but I wanted to see why this doesn't work. – Freedom Jul 12 '16 at 19:14
  • The %cd% variable may for some reason be uninitialized so I have offered an alternative to that. – Paul Stelian Jul 12 '16 at 19:16
  • 1
    I may have got confused, but this confusion is actually something granted to me: On Stack Overflow, you don't ask for someone else to write your code. Instead, you provide your own code, which may or may not work, give an example where it doesn't work and ask us to fix it. – Paul Stelian Jul 12 '16 at 19:17
  • You should actually mention exactly what you wish. Not give other stuff. – Paul Stelian Jul 12 '16 at 19:18