ls and cd commands not working with Cygwin - python

I am trying to use Cygwin to run my first python program. I downloaded python and Cygwin. Within the Cygwin terminal I ran the command: "which python" to confirm that the terminal could find python. However when I attempt to cd into my Desktop for example, I get "-bash: cd: Desktop: No such file or directory". When I try to do an ls, it simply returns an empty line. For some reason "pwd" works normally.
I am having a problem similar to the one here: Cygwin ls command not found
However changing the environmental variables has no effect (even after I closed and repopened the terminal window).

Make sure C:\cygwin64\bin or its equivalent is set as a path variable.
Run mintty.exe as administrator and enter: mkpasswd -l -p "$(cygpath -H)" > /etc/passwd
Close mintty.exe and access it again through the Windows shortcut 'Cygwin64 Terminal'. This is auto-generated during setup. The shortcut target should be set as the path to the bin which contains mintty.exe C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -.
Hope this helps!

Related

run bash command in python script and make sure it runs [duplicate]

How can I run .sh on Windows 7 Command Prompt? I always get this error when I try to run this line in it,
app/build/build.sh
error,
'app' is not recognized...
or,
bash app/build/build.sh
error,
'bash' is not recognized...
Any ideas what have I missed?
Here the screen grab,
Install GIT. During installation of GIT, add GIT Bash to windows context menu by selecting its option. After installation right click in your folder select GIT Bash Here (see attached pic) and use your sh command like for example:
sh test.sh
The error message indicates that you have not installed bash, or it is not in your PATH.
The top Google hit is http://win-bash.sourceforge.net/ but you also need to understand that most Bash scripts expect a Unix-like environment; so just installing Bash is probably unlikely to allow you to run a script you found on the net, unless it was specifically designed for this particular usage scenario. The usual solution to that is https://www.cygwin.com/ but there are many possible alternatives, depending on what exactly it is that you want to accomplish.
If Windows is not central to your usage scenario, installing a free OS (perhaps virtualized) might be the simplest way forward.
The second error message is due to the fact that Windows nominally accepts forward slash as a directory separator, but in this context, it is being interpreted as a switch separator. In other words, Windows parses your command line as app /build /build.sh (or, to paraphrase with Unix option conventions, app --build --build.sh). You could try app\build\build.sh but it is unlikely to work, because of the circumstances outlined above.
The most common way to run a .sh file is using the sh command:
C:\>sh my-script-test.sh
other good option is installing CygWin
in Windows the home is located in:
C:\cygwin64\home\[user]
for example i execute my my-script-test.sh file using the bash command as:
jorgesys#INT024P ~$ bash /home/[user]/my-script-test.sh
you can use also cmder
Cmder is a software package created out of pure frustration over the absence of nice console emulators on Windows. It is based on amazing software, and spiced up with the Monokai color scheme and a custom prompt layout, looking sexy from the start
cmder.net
On Windows 10 Anniversary Update, it's even easier to run shell commands in/with bash on ubuntu on windows
I was trying to set my region for my x-wrt r7000 netgear router, I found the following worked for me, using bash on ubuntu on windows, you do have to enable subsystem found in windows features, and dev mode on
ssh admin#192.168.1.1 < /mnt/c/ccode-eu.sh
Install the GitBash tool in the Windows OS. Set the below Path in the environment variables of System for the Git installation.
<Program Files in C:\>\Git\bin
<Program Files in C:\>\Git\usr\bin
Type 'sh' in cmd window to redirect into Bourne shell and run your commands in terminal.
New feature in Windows - run bash on ubuntu on windows - available in Windows 10 "Insiders" builds after the Build conference:
https://blogs.windows.com/buildingapps/2016/03/30/run-bash-on-ubuntu-on-windows/
Personally I used this batch file, but it does require CygWin installed (64-bit as shown).
Just associate the file type .SH with this batchfile (ExecSH.BAT in my case) and you can double-click on the .SH and it runs.
#echo off
setlocal
if not exist "%~dpn1.sh" echo Script "%~dpn1.sh" not found & goto :eof
set _CYGBIN=C:\cygwin64\bin
if not exist "%_CYGBIN%" echo Couldn't find Cygwin at "%_CYGBIN%" & goto :eof
:: Resolve ___.sh to /cygdrive based *nix path and store in %_CYGSCRIPT%
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%~dpn1.sh"') do set _CYGSCRIPT=%%A
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%CD%"') do set _CYGPATH=%%A
:: Throw away temporary env vars and invoke script, passing any args that were passed to us
endlocal & %_CYGBIN%\mintty.exe -e /bin/bash -l -c 'cd %_CYGPATH%; %_CYGSCRIPT% %*'
Based on this original work.
just install git and by "bash <name.sh>" run your .sh file.
I use Windows 10 Bash shell aka Linux Subsystem aka Ubuntu in Windows 10 as guided here
Have you tried cding to the root directory where your .sh is located in order to execute it from there, instead of writing down a path to the file as you showed in your question?
Like so:
$ cd app/build
$ build.sh

PyCharm Terminal - use Git Bash

Goal: use Git Bash as Terminal in PyCharm.
How can I have a normal Bash with Git integrated Terminal in PyCharm?
File path for Git Bash: C:\Users\me\AppData\Local\Programs\Git\git-bash.exe --cd-to-home.
I apply Git Bash in PyCharm Settings:
However, when I click New Session (new Terminal +), it launches as a Window:
You are pointing at git-bash.exe, which is wrong. You should point at bash.exe which is located inside the bin folder. So your Shell path should be:
"C:\Users\<username>\AppData\Local\Programs\Git\bin\bash.exe" --login
using
"C:\Users\<username>\AppData\Local\Programs\Git\bin\sh.exe" --login
would also work. Also works without --login. Make sure the " are there.

Anaconda and Git Bash in Windows - conda: command not found

I've installed Anaconda and set Path environment variable to C:\Anaconda3; C:\Anaconda3\Scripts.
Then I try to run in Git Bash
conda install python
But there is an error message "bash: conda: command not found". I would like to know why.
To be able to run conda on gitbash you need to add it to the path. Many times I've seen that's done by default - as shown in the setup for this workshop. If it doesn't, as it seems your case, then you can run their setup directly by running:
. /c/Anaconda3/etc/profile.d/conda.sh
After running that you should be able to run conda commands.
To keep this setup permanently you can add such line on your .profile or .bashrc file (read more about their differences). A way of doing so is running the follwing:
echo ". /c/Anaconda3/etc/profile.d/conda.sh" >> ~/.profile
You may encounter problems if the path where Anaconda was installed contains spaces (e.g., C:\Program Files). In that case you would need to change the anaconda location or edit conda.sh script with something like:
sed -e '/^_CONDA_EXE=.*/a alias myconda="${_CONDA_EXE/ /\\\\ }"' \
-e 's/\$_CONDA_EXE/myconda/g' /c/Program\ Files/Anaconda3/etc/profile.d/conda.sh > conda_start.sh
This sed command inserts a new alias definition myconda which changes the anaconda path from Program Files to Program\ Files so bash doesn't stop with an error like this one:
bash: /c/Program: No such file or directory
The second sed command replaces the _CONDA_EXE variable by the new alias created.
Since the above doesn't modify the file provided by anaconda, you will need to update your .profile file to load the file we've just created, conda_start.sh, instead.
First, you need to move to the directory where conda is located.
(some path such as C/Anaconda3/Scripts or ../miniconda3/Scripts or anaconda3/bin)
then, open the terminal.
(or, if you use Windows and can't find where the conda is, try moving to directory such as C:\Users\User_Name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit) and open the Anaconda prompt.)
Then, do this:
conda init
or something like
conda init bash
if you use Mac OS:
conda init zsh
will work well.
if you wanna use different shell,
conda init [shell_name]
[shell_name] can be: bash, cmd.exe, fish, powershell, tcsh, xonsh, zsh, etc.
use conda init --help for more info.
Joining #dvdgc13. In my case, I fixed the problem by adding
. C:/Users/user/Anaconda3/etc/profile.d/conda.sh
to my .bash_profile.
I tried to do the same thing as you did but I couldn't get it to work. starriet had the working answer but I am going to make it easier for everyone else reading. You can directly open command windows with explorer instead of struggling with paths.
Find your Anaconda3 folder with Windows Explorer This could be a user install where would be in your user folder such as "C:/Users/your_name/Anaconda3".
Shift + Right Click on the explorer and click on "Open PowerShell Windows Here". Note: you can just click "Git Bash" and you open Bash instead which makes no difference to the command.
Type in "conda init" in the PowerShell window. This works even if you don't have the right paths because the command line looks for the right exe in the current dictionary. If you scroll down in the explorer, you should be able to find it.
My PowerShell window would look a little different than yours because of my prompt but it makes no difference.
Exit the PowerShell and open Git Bash. Type "conda" to confirm that things work.
For MAC users, do this:
$ echo ". /usr/local/anaconda3/etc/profile.d/conda.sh" >> ~/.bashrc
$ source ~/.bashrc
I tried many ways, but they are incomplete until I run the following commands:
Go to the path of anaconda3 is C:\Users\USER_NAME\anaconda3 and open commend line over there and print the following: (YOUR_PATH = C:\Users\USER_NAME\anaconda3 )
echo 'export PATH="$PATH:[YOUR_PATH]:[YOUR_PATH]/Scripts"' >> .bashrc
echo 'alias python="winpty python.exe"' >> .bashrc
If Git bash is opened, close it and reopen it again and type the following to make sure anaconda and python work without problems:
conda --version
python -- version
If you see the versions are printed, everything works well.
In my case conda command was recognised in cmd, but not in bash. I used conda init bash instead of simple conda init in cmd.
This command modified the .bash_profile file, which was residing in my C:\Users\xyz directory, and added the following code in it
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
eval "$('/C/Users/Saifullah/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
# <<< conda initialize <<<
now it is working in bash terminal too.

Where is the .profile file on mac?

I have a MacBook Pro 13` inch (without touch bar) and it is running mac os sierra. I have installed Xcode, command line tools and homebrew. Now I want to install python 3 and make it a default interpreter when calling it from the terminal. I have found this guide http://docs.python-guide.org/en/latest/starting/install3/osx/ and I get confused when they say I should add the path to the ~./profile but I don't know where to find the file. Can somebody help with step by step guide on how to create it if it not there?
Thanks
I felt to add something here that ate a lot of my time when I had a similar issue.
Many a times the .profile or the .bash_profile (in case of bash shell) is not present. This is typically when you have freshly installed the OS or when you're on a new machine. This gets confusing as one may think if the installation wasn't correct etc. Nothing to worry about. If you don't find these files then simply create it new using vi or whatever means (GUI) and you're good to go. Having a shell doesn't mean you have these files too and you have to create it yourself if you're the first one to use it.
The file you are looking for depends on your shell, so if you are using bash, which is the default shell on Mac systems, it will be either ~/.bash_profile, or ~/.bashrc depending on whether you are in a login shell or non-login shell respectively.
Mac Terminal runs a login shell every time a new terminal window is open, and it calls .bash_profile, so you should use ~/.bash_profile.
On Mac, zsh is the default shell. You can check this by running
echo $SHELL
If so, you can check for ~/.zshrc if not you can create one and add required commands, alias which need to run during the terminal startup.
Then you can run
source ~/.zshrc
This will be executed every time the terminal is opened.
It could be that you are not running bash (rather an extended version like zsh, ksh, etc)
If you are running bash shell, then you should be able to see ~/.bash_profile, or ~/.bashrc or ~/.profile.
Incase of zsh shell, you would see .zprofile or .zshrc
You can check what shell you have by echo $SHELL
After you install "Brew", there is a prompt in the terminal that says: "Next Steps:"
Follow those steps!

OSX: Setting Enthought python path in .bash_profile results in weird terminal behavior

I followed the knowledge base on adding this to the .bash_profile
PATH="~/Library/Enthought/Canopy_64bit/User/bin"
export PATH
When I then restart the Terminal, a lot of functions do not work anymore:
X:~ excuvator$ ls
-bash: ls: command not found
X:~ excuvator$ security
-bash: security: command not found
X:~ excuvator$ sudo
-bash: sudo: command not found
However, enpkg and cd still seem to be callable. If I remove that part, stuff works again. Does anyone have any insight to what is happening? I just want to get enpkg running...
You reset PATH, rather than adding to it, so bash doesn't know any place to look for commands other than the single directory you specified. Instead, use one of
PATH=$PATH:~/Library/Enthought/Canopy_64bit/User/bin
or
PATH=~/Library/Enthought/Canopy_64bit/User/bin:$PATH
Which of the two assignments you use depends on whether whether you want the new directory to be the first or last place the shell looks for a named command.
enpkg actually is in that directory, and cd is a shell built-in command, not an external program, so no path lookup is involved.

Categories