Trying to create a more advanced alias (Linux) clone for Windows in a batch script

  alias, batch-file, cmd, doskey, windows

I am attempting to write a batch script to create an alias command similar to the one in Linux, I couldn’t find one online that was exactly what I was looking for, or as complete as I was looking for, so I began piecing together my own, even though I’m relatively new to batch scripting. I can’t figure out what’s wrong with my batch script.. Here is the code, any ideas?:

shimmer.bat:

@echo off
echo.
echo Shimmer Alias Creator initiated...
      if ["%~1"]==[""] (
        if ["%~2"]==[""] (
      if exist %APPSHIMSDIR%%~s1.bat (
        echo Error: There is an existing shim-alias with the name %~s1. Please specify a unique name for your shim-alias.
        goto :end
      ) else (
        if exist %~s2 (
          goto :createshim
        ) else (
          echo Error: The file you entered to link your shim-alias to does not exist...
          goto :end
        )
     ) else (
       echo Error: You did not enter a valid application path to link your shim-alias to...
       goto :end
    ) else (
      echo Error: You did not enter a valid shim-alias...
      goto :end
    )
      )
)
    goto :end
      
:createshim
    echo @echo off > %APPSHIMSDIR%%~s1.bat
    echo start %~s2 %%* >> %APPSHIMSDIR%%~s1.bat
    echo exit >> %APPSHIMSDIR%%~s1.bat
    echo Successfully created %~s1 shim-alias for %~s2...
    goto :end
:printhelp
    echo Create a command-line shortcut-alias that links to a program to be executed.
    echo.
    echo Usage:
    echo "SHIMMER [/? | --help] [alias-name] [path]"
    echo.
    echo "/?        Displays this usage documentation"
    echo help   Displays this usage documentation
    echo alias-name The desired shim-alias to be used to link to your program
    echo path   The full path to the program to be executed via your shim-alias
    echo.
    echo Example of usage:
    echo.
    echo SHIMMER shimname C:ProgramDataMyAppMyApp_x64.exe
    goto :end
:end
exit /b

I added the path I wanted to keep my alias/shims in to my PATH for %APPSHIMSDIR%..

I want to be able to use it like so

shimmer myapp C:PathToMyApp.exe

Then be able to use myapp with whatever commands I need whenever like this

myapp -example --e

Source: Windows Questions

LEAVE A COMMENT