-1

I got Gnu Utilities that adds the command sed to windows, but to use it I have to type:

C:\ProgramFiles\GnuWin32\bin\sed.exe <args>

How do I shorten this to just sed <args>?

Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54

1 Answers1

2

To run an executable without a full path, it needs to be either in the current directory, or in the PATH environment variable. In the CMD prompt, there are several ways to do this.

The first way is to put C:\ProgramFiles\GnuWin32\bin in your PATH variable, which makes every program in that directory available without a full path.

set "PATH=%path%;C:\ProgramFiles\GnuWin32\bin"

This updates PATH in the current command prompt. If you need to set it for other CMD windows, see How to persistently set a variable in Windows 7 from a batch file?

The second method is to have sed.exe in the current directory. The most obvious way to do that is to change directories.

cd C:\ProgramFiles\GnuWin32\bin
sed

Or you can copy it to your current directory.

copy C:\ProgramFiles\GnuWin32\bin\sed.exe .\
sed

(This works with sed.exe because it's a self-contained utility. Don't try this with a Windows application like excel.exe)

Finally, you can create a "redirect" somewhere in the current directory or the path.

>.\sed.bat echo C:\ProgramFiles\GnuWin32\bin\sed.exe %*

This creates a batch file in the current directory called sed.bat that calls the full sed.exe. You can drop this file into any directory in your PATH.

mklink .\sed.exe C:\ProgramFiles\GnuWin32\bin\sed.exe

This creates a symlink to the sed.exe in the current directory, much like a symlink in Unix or a shortcut in Windows.

Community
  • 1
  • 1
Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54