attempting to assign alias to path of an exe file in dos shell - bash

I want to set an alias to my installation of firefox so I can easily start a web page, the problem is that I dont want the script to be system dependent.
Namely I want it to be able to run on a linux distribution where the command to start firefox is already mapped to 'firefox' and can easily be run that way through bash, but on my windows machine I cant seem to get it to assign to the same variable.
I saw that I could set it to '%firefox%' via the set command but that's not quite what I want.
I believe creating aliases is possible on a windows environment because the version of svn that I use auto-installed and was able to assign itself to 'svn'. Anyone know what was involved in them being able to get their alias working, or a similar way to alias a command?

If you include your Firefox path in the %PATH% environment variable, you can start FF with "firefox". Under Windows, you should edit the system-wide settings (see this link).
AFAIK, there is nothing similar to aliases under DOS/Windows (except the %firefox% way you mentioned, too). The 'svn' command you talked about most likely is the same thing, a 'svn.exe' and its path included to %PATH%.
This is a bit restrictive, as you can only use the original filename to launch a program, but you can work around this by creating a batch file in the program's path that launches the program, f.e. a FF.BAT that contains "firefox %1".
Alternatively, you can place a batch file in a path that already is in %PATH%, f.e. the Windows directory. That way, you don't have to modify %PATH%.

Related

What is the difference between the PATH listed by 'env' in git-bash and the PATH in Windows 10's control panel?

My goal is to write a shell script that will ensure that a bunch of Windows 10 computers with Python freshly installed on them can run the 'python' command from a git-bash command line in Windows Terminal by having the script check the PATH environment variable and modify it if necessary.
More specifically, I want my script to check if the following three paths are part of each computer's PATH, and if they aren't already a part of it, edit the PATH so that it permanently contains them.
C:\Program Files\Python311
C:\Program Files\Python311\Scripts
C:\Users\ <localUser>\AppData\Roaming\Python\Python311\Scripts
What threw me off is that I noticed that the PATH variable that I get from the 'env' command on the git-bash command line is different from the PATH variable that I can see in Windows 10's control panel. I tried adding a junk path to PATH from the command line by typing
export PATH=/c/someNonexistentPath in git bash but it didn't change the PATH that I could see in the Windows 10 control panel. Moreover, I couldn't even see if it changed the PATH I get from running env on the command line because for some reason after you run any export command git-bash gets amnesia and refuses to recognize the env command until you start a new session of git-bash.
Shouldn't there only be one PATH on a computer? If the two seemingly different PATHs that I have mentioned are not supposed to be the same, what is the difference between them, and how can I accomplish my goal of writing the script so that it does what I need it to do?
Please let me know if I need to include any more system-specific info. Thanks in advance for your help.

How to run zookeeper.sh file in windows

I am following this tutorial where i have to run this command in order to start the zookeeper server.
./bin/zookeeper-server-start.sh config/zookeeper.properties
But the problem is this command is not working properly. I found that .sh file is bash file that required cygwin. I have installed it and then run command like this
C:\cygwin64\bin\bash.exe ./bin/zookeeper-server-start.sh config/zookeeper.properties
But it is showing:
I can confirm that in bin directory the file is exsits. what i am doing wrong?
Here is my directory snapshot from where i running the command:
Note: I have successfully tested bin/windows zookeeper bat file but i want to run it through .sh file as the kafka security tutorial which i am following using this.
From your screenshot, I conclude that you are using Cygwin. So, please add the cygwin tag to your question.
As you can see from the error message, the command dirname is not found by bash, so assuming that your Cygwin installation is not broken, I assume that the PATH is not set correctly; in your setup, dirname.exe should be in C:/cygwin64/bin (please verify this).
Your usage of bash.exe is a bit unusual in that you run it directly from a Windows cmd prompt. The more common way would be to use it from the 'Cygwin Terminal', which you get created a Windows-link to, when installing Cygwin, or to use another suitable Terminal program; I'm using for instance mintty for this task (also available via the Cygwin installer).
Having said this, it is possible to run bash.exe in the way you are doing it, but you then have to ensure, that at least the PATH is set up correctly. One possibility to do this, is to add C:\cygwin64\bin to your Windows PATH, but this has the drawback, that some commands have the same name in the Windows world and in Cygwin, though they serve a completely different purpose, and this will bite you sooner or later. Another problem is that at some point, you will rely on other bash specific setups besides the PATH.
A better way to accomplish your goal is IMO to ensure, that the system wide bash-initialization files are sourced by bash. If I have to run the script from a Windows cmd prompt, I would run it by
C:\cygwin64\bin\bash.exe --login YOURSCRIPT
This will read the file (in your setup) C:\cygwin64\etc\profile before running YOURSCRIPT, so you can check, that the PATH is correctly set there, by looking at this file. In a default installation, this should be the case.
After having read this file, it will try to read the file .bash_profile in your Cygwin HOME directory, so if you need additional settings for your (non-interactive) bash-scripts, create this file and put your settings there.

installed program "cppcheck" but command "where cppcheck" (on windows command line) can't find anything

I downloaded and installed the program "cppcheck" (http://cppcheck.sourceforge.net/).
This program has both a GUI (which I can access without problems) and a command line interface.
However, when I go to the windows command prompt and type "where cppcheck", nothing can be found.
Am I crazy? Or is the command line interface for cppcheck only accessible on Unix systems?
Since I usually don't work with Windows, I didn't realise that the "where" command just looks in the current folder and child folders of the current folder. That's why I didn't get any results.
You have to add it in the environment variables since the cppcheck installer does not add it automatically. This way you can use the where command from any folder as it also checks the environment variables too.

Run command to go to user's documents folder (similar to %appdata%)?

Putting %appdata% into the run window will open up the Appdata folder, but what is the command to open the User's Documents folder, even when someone else logs in? I thought it was something like %userdir%, but I can not find out what it is. Not sure what to search for in Google either so I am at a loss.
There is no environment variable for this. You'll need to set one. Here's a list of all Windows default environment variables:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true
*This is for XP, but should be the same for newer versions of Windows
For a single terminal session, you can just use
set USERDOCS=%USERPROFILE%\Documents
For all terminal sessions, you'll need to set a system environment variable. You can do this using the GUI or using setx -m USERDOCS %USERPROFILE\Documents, as described here.
The command to make this happen would be
explorer %USERDOCS%
But if you wanted to make an alias to that (i.e. a openuserdocs command), I can update and explain.

How do I run a global command with same name as a file in the working directory on windows?

I want to run a command that is installed and available globally on my cmd.exe commandline.
This usually works fine, except when I run it in a directory that has a file with the same name as the command.
So any time I use this command in this particular directory my windows is trying to open this file in whatever application is registered for this extension.
It is very annoying, but there must be a way around this right?
I tried it with a bunch of names, like ping.txt and they all open the files intead of running the command.
That's not normal behaviour in the default configuration; sounds like the PATHEXT environment variable has been modified.
You could either change it back to the default,
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
or explicitly type ping.exe (for example) instead of just ping.
If the file name is EXACTLY the same (including the same extension, i.e. ".exe"), then I believe the only way around this is to specify the full path to the file you WANT to execute. For example, if the program you want to execute is explorer.exe, but you have a file named explorer.exe in your current directory, you have to specify \Windows\explorer.exe to run Windows explorer.

Resources