installing winbash on win7: "ls" works, but "clean" cmd not working? - bash

After installing win-bash from sourceforge.net and creating a command prompt label and setting the path, my bash recognizes some commands like "ls", "mkdir" but not "clear" or "clean"!
the label to command prompt has this in its properties:
the red arrows points to this setpath.bat, it has this:
#echo off
SET PATH=%PATH%;C:\win-bash
bash
exit
the folder win-bash has the content from win-bash downloaded file from sourceforge + setpath.bat file.
My bash recognizes ls, mkdir - creates folders, but can't "clean". What's the reason - some shell cmds recognized, and some don't?!
P.S. It does NOT recognize most commands - mkfile, lsblk, calendar(cal)

Not an expert on win-bash, but here are some clues:
other linux emulators on Windows like mingw32, GoW provide standalone executable .exe for each program, so it is easy to see which commands are implemented just by reviewing the emulator directory (the one it appends to path)
win-bash claims from documentation it is a single-file replacement for the shell, but rest of documentation is limited
if you want to clear screen 'cls' should work it is a native windows command. On internals of 'clear' see
https://superuser.com/questions/1161514/bash-on-ubuntu-on-windows-clearing-all-the-text-all-of-it

Related

Running shell script on Windows via Cygwin mintty.exe doesn't execute runcoms

Problem summary
I'm trying to launch a .sh script via Windows 10 Cygwin (i.e. mintty.exe > bash.exe) but neither .profile, .bash_profile, or .bashrc are loading, which I need to update PATH env variable with Cygwin's bin directory.
Background
I'm trying to launch a script finder.sh:
#!/bin/bash
find .
read
from C:\Users\Bo\Temp\. It has unix line endings and executable bit set.
I have Cygwin installed at C:\Users\Bo\AppData\Local\Programs\cygwin64\. I do not have this path in either System or User Windows' Environment Variables (and I don't want to!). My runcoms all live in this directory under /home/Bo. My .bash_profile (and ATM .bashrc) have an export PATH="/cygdrive/c/Users/Bo/AppData/Local/Programs/cygwin64/bin":${PATH} in them.
I want to launch the script from Windows Explorer. I tried using the bash.exe and mintty.exe in the cygwin64\bin\ folder via Open > Choose another app > More apps > Look for another app on this PC. In either case the mintty window displays:
FIND: Parameter format not correct
meaning the Windows' find command was used not Cygwin's. So I have my script echo $PATH and the Cygwin/bin directory is not in PATH. If I add the proper export PATH statement from above to my own script it works fine. So, now to debug the launcher and runcoms...
I've put echo ${0} statements in .profile, .bash_profile, and .bashrc, none of which trigger which I run the .sh script, they are never run. I've read SO and the mans. I've tried creating a Shortcut to both mintty.exe and bash.exe passing a variety of -l -i -e - commands to each using Properties > Shortcut > Target and they are never run. E.g. running simply [..]\mintty.exe -h always doesn't even leave the window open.
How do I get my script to run in Windows Explorer via Cygwin's mintty.exe/bash.exe, and to read from a runcom to update PATH (to find Cygwin Linux commands, vs. updating Windows Environment Variable)?
Two part fix:
A) set a Windows Environment Variable for BASH_ENV to a .bash_env under your Cygwin HOME, and export the PATH variable to include the Cygwin/bin directory from that file. I cannot find a decent reference for this in Cygwin documentation because it seems to be simply a bash thing, but this variable is what bash looks for when running non login/interactively. Best reference: Cygwin shell doesn't execute .bashrc.
And B) run the .sh with bash.exe from Cygwin/bin using Open With....
ALSO, annoying Windows bug: when you select a program to Open With... your .sh script, it will always run 1x with a CWD from your C:\Windows\System32 directory(?!) and all other times will run fine with the CWD as the directory from your .sh script.

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.

How can I open a cygwin terminal?

I'm using a windows 8 and have cygwin installed. However, when I navigate to the folder it's contained in, the only subfolders are usr and var, and neither contains something that looks like a terminal. How can I open a cygwin terminal?
You should use mintty executable for this. In case of a default install path it is located here: c:\cygwin\bin\mintty.exe
Cygwin installation puts a shortcut to the start menu, but perhaps this feature was broken in win8.
I checked this shortcut on my computer, and it contains this command as a "Target":
C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -
You should create a shortcut like this. Replace the given path, if your cygwin is located anywhere else. -i command line argument is not necessary. For further info check the manual page of mintty, which is located here.
You can run
c:\program files\cygwin\bin\bash.exe
inside the Windows CMD.
When you install cygwin, it normally installs a ".bat" file at the top of the directory-tree containing cygwin, which can run a command-window. For example:
#echo off
C:
chdir C:\cygwin64\bin
bash --login -i
The exact location of the cygwin tree is relevant to the script, of course, and details change occasionally. But the bash executable, starting in cygwin's bin-directory is enough to start a window.
Outside cygwin, you will not see things such as mounted directories and symbolic links. So (from the Windows file explorer) it may look incomplete.

How to start GNU Octave with GUI through Cygwin from a desktop icon?

Since GNU Octave comes wit a GUI since versions 3.8.0, I thought I should check it out.
So since I run Windows and could only find Octave 3.8 for Cygwin, I installed Cygwin and the packages octave, xinit, xlaunch and gnuplot (according to this page, but I don't know if all those packages are needed).
Then, when trying to start Octave with the GUI from Cygwin with octave --force-gui, I initially got the error message
octave: X11 DISPLAY environment variable not set
and Octave would start in console mode. So I found this page, which told me to run
echo "export DISPLAY=:0.0" >>~/.bash_profile
from Cygwin, to permanently get rid of the error message, which worked. However, then I instead got this error message:
octave: unable to open X11 DISPLAY
The same page also said that you have to run the X Server by going to Start -> Cygwin-X -> XWin Server. That worked, but since I don't want the xterm terminal to start since it is not needed, I found this page which told me to run
touch ~/.startxwinrc
from Cygwin to create an empty .startxwinrc file, to prevent the xtrem terminal from starting by default, which worked. The same page also mentioned that the X Server can be started directly from Cygwin with the command startxwin.
So, now I can start Octave with the GUI from Cygwin, simply by running
startxwin
octave --force-gui
However, I would like to just be able to double click on a desktop icon to get everything up and running.
So, to my question: Can I somehow put this in a script file, which when I run it, will be opened in Cygwin so that the commands in the script file will be run in Cygwin? And is there some way to automatically close the X Server after Octave has terminated? I've tried writing a file octave.bat, which starts Cygwin and gives a second batch file as argument, which in turn contains the commands I want to execute. But when I run the first script, I just get bombarded with command prompts (not Cygwin prompts), and the all say
'startxwin' is not recognized as an internal or external command, operable program or batch file.
Why is the second script not opened in Cygwin, and how can I achieve what I want as simply as possible?
Please grab Octave from here: http://mxeoctave.osuv.de/
The installer should configure everything for you.
GNU Octave offers now Windows binary itself. Go to ftp://ftp.gnu.org/gnu/octave/windows/
You have to put
c:\cygwin64\bin\mintty.exe /bin/sh -lc 'startxwin /bin/octave --force-gui'
in your windows batch file (please adapt the Cygwin path to your settings). That worked fine for me.
The call
c:\cygwin64\bin\bash --login -c "startxwin /bin/octave --force-gui"
did open Octave as desired but the GUI seemed to have response issues to the keyboard and froze after clicking into the editor.
I don't have any of the those commands installed with my Cygwin installation, so I can't test this by trying using the following an .bat file on your desktop:
c:\cygwin\bin\bash --login -c "startxwin octave --force-gui"
Replace c:\cygwin with the directory where you installed Cygwin.
If this leaves a console window on the screen try doing:
c:\cygwin\bin\bash --login -c "run startxwin octave --force-gui"

'gitk --all' command not being recognized in Windows 8 Powershell

gitk is not working for me. I get the error saying "the term 'gitk' is not recognized as the name of a cmdlet, function, script file, ...."
One interesting thing I noted was that inside C:\Program Files(x86)\Git\bin\, there was a gitk file, but it had no extension. Most other files in that folder had a .exe extension.
I also made sure that C:\Program Files(x86)\Git\bin\ is specified in the PATH environment variable.
Also, I tried adding C:\Program Files(x86)\Git\cmd\ to PATH because it contains a gitk.cmd file, but that did not help either.
Edit : I was using Powershell earlier, since I have poshgit installed. I switched over to bash, and I was able to do gitk --all from there.
I just got it to work after having the same problem.
At the PowerShell prompt it typed: "Bash" and hit return.
This put me into a bash shell.
Then I typed "gitk" at the Bash prompt and it worked.
So that gitk file is a UNIX shell script and requires the shell to work.
I suppose you could always have one of your Power Shell window in Bash mode and then this tool is available.

Resources