Added to ~/.bash_profile
PATH=c:/Python27:$PATH
and
env | grep PATH
shows the path c:/Python27
However I cannot run python interpreter from command line in bash. I'm on Windows 7 and I can run python from any directory in command prompt after doing
path %path%;C:\Python
Or adding the path to my Environment Variables
In bash I am able to do other commands from any directory in terminal after adding their path to ~/.bash_profile given the path is a sub-directory of ~/
If the path in .bash_profile is C:/ rather than ~/ it doesn't work. So my question is when adding a path to .bash_profile where the location is in C:/ rather than ~/ how do i do it?
Bash uses : as the path separator, so you actually just added "c" and "/Python27" to your PATH.
Different Windows GNU toolset ports have different ways of working around this. You can try ls /c/, ls /cygdrive/c or read your port's documentation to see how it handles this.
If you find that e.g. /c/Python27 is mapped to c:\Python27, then you can add that to your path instead.
Related
I am trying to permanently add a binary to the path variable on mac os. I have read several posts and blogs, it just does not work.
The question: given a directory /dir which contains an executable foo, how can I make it such that I can execute foo in the commandline without having to type export PATH... etc., and without having to move the foo executable to the bin folder?
I know there exists several scripts that are run on startup and whenever you open a command prompt, I just cannot seem to find the correct one. If I manually execute the export PATH... command and then do foo, it works.
If the export command works for you, just add it to either ~/.zshrc (on zsh) or ~/.bashrc (on bash).
I am using ConEmu 64bit with Cygwin 64bit on a Windows 7 machine.
I don't want to set the working directory for cygwin in my .bashrc, as I like to setup more than one Task for Cygwin with different path parameters.
I set up the "home directory" in the task parameters:
\dir "D:\Downloads\Programming\Selenium\"
and added this line in the commands window:
C:\cygwin64\Cygwin.bat --login -i
Nevertheless Cygwin does not start in the "cygwinized" version of the given directory (/cygdrive/d/Downloads/Programming/Selenium) but in "normal" home directory of my user (~).
I only found howto's on how to add a new path in bashrc. Maybe one of you can enlighten me.
First of all, have you look at contents of your C:\cygwin64\Cygwin.bat? Why not?
#echo off
C:
chdir C:\cygwin64\bin
bash --login -i
Obviously, Cygwin.bat will never open bash in your desired dir.
Also, Cygwin ignores user defined startup directory! That is because cygwin always do cd "${HOME}" from /etc/profile script.
But, for example, bash from msysgit works properly.
Solution
However, /etc/profile script checks for CHERE_INVOKING environment variable before CD doing. So, the proper command line for starting cygwin will be:
set CHERE_INVOKING=1 & c:\cygwin64\bin\sh.exe --login -i
Another workarounds you may find in the project wiki page.
I had a similar demand (opening a new Cygwin-Tab in the folder currently viewed in explorer via the context menu) and found the following solution:
As stated by Maximus the Cygwin-Bash is usually opened by C:\cygwin64\Cygwin.bat which includes the login process. My approach was to change the working directory through the login.
.bash_profile:
if [ -f "${HOME}/startup.sh" ] ; then
source "${HOME}/startup.sh"
fi
startup.sh
cdc "D:\Downloads\Programming\Selenium\"
#cdc is a custom function, see .bashrc
.bashrc
cdc()
{
# converts a double-quoted windows-path and changes directory to it
p=$(cygpath -u "$1")
cd "$p"
}
The login progress thus changes the path of you bash to the one you've set in startup.sh. You might of course just type a Cygwin-compatible path in startup.sh without using the custom-function of .bashrc. It's still quite useful, especially if you want to want to use a dynamic startup.sh.
More Dynamic-approach:
Create a Cygwin.bat in C:\opt\ConEmu\ConEmu with the following content:
Cygwin.bat
#echo off
C:
echo cdc %1 > C:\opt\cygwin64\home\%USERNAME%\startup.sh
:: Your ConEmu-Task-definition here
C:\opt\ConEmu\ConEmu64.exe /Single /cmd {Cygwin}
This one writes a cdc-command followed by the path you provide into your startup.sh and starts an new instance of the ConEmu-Task Cygwin. The task itself does not do anything but starting an instance of Cygwin in my configuration:
ConEmu Task {Cygwin}
"C:\opt\cygwin64\Cygwin.bat"
I invocate the Cygwin.bat through the context-menu of the explorer. Another way would be to make a Windows-Shortcut pointing to Cygwin.bat with you path appended.
I have used export before but I don't know why when I set the variable PATH to any directory this time, ls, awk commands are not found but no problem with pwd, cd
export PATH="/Users/carolW/Desktop"
ls
-sh: ls: command not found
Use:
export PATH=/Users/carolW/Desktop:$PATH
You're removing all the normal directories from your path, so it only looks in your Desktop folder for everything. You just want to add your directory, not replace the entire path with it.
most probably because pwd and cd are built shell command
(you can test:
which pwd
which ls
)
However, ls are such are tools you can find in /bin directory or such, and those paths are defined in your variable PATH.
If you clear the variable PATH, most likely you won't find your tool anymore.
You may use export PATH=$PATH:"/Users/carolW/Desktop"
So that you concatenate your path to the already existing paths
I am on Mac's OS 10.6, and I am trying to learn a thing or two about shell scripting. I understand how to save a shell script and make it executable, but I am wondering what I can do or where I can save the file to make it global (that is, accessible no matter what folder I am in).
For example, if I save a .sh file in the /Users/username/ directory and make it executable, I can only execute that script in that specific directory. If I navigate to /Users/username/Downloads, for example, I can't execute the script.
Also, any suggestions of resources for learning more about shell scripting would be helpful. Thanks
/usr/local/bin would be the most appropriate location. Mac OS X has it in the PATH by default
There are two ways to do it -
Put your script in usr/local/bin and make sure it is executable(chmod +x my_script)(This is already set in the path, you can check by doing an echo $PATH)
Create a folder in your home directory called bin. (For your personal scripts)
cd ~ (Takes you to your home directory)
mkdir bin (create a bin folder)
vim .bash_profile (to set path environment variable)
export PATH=~/bin:$PATH (Press i then add this line and then do esc and type :wq)
Now you can just type the name of your script and run it from anywhere you want.
** NOTE: If you want to run the script with a shortened command rather than typing your entire filename, add the following to your .bash_profile:
alias myscript='my_script.sh'
Then you can run the script by simply typing myscript. (you can sub in whatever alias you'd like)
Traditionally, such scripts either go in ~/bin (ie: the bin directory in your home directory) or /usr/local/bin/ The former means the script will only work for you, the latter is for scripts you want anybody on the system to be able to run.
If you put it in ~/bin, you may need to add that to your PATH environment variable. /usr/local/bin should already be on the path.
In mac operating system
Open bash ~/.bashrc file.
add path of your script in your bashrc file , using
export PATH="$PATH:/Users/sher.mohammad/Office/practice/practiceShell"
Open your ~./bash_profile file and add [[ -s ~/.bashrc ]] && source ~/.bashrc
open new terminal window
Now whenever you will open your terminal your script will be loaded
This one is super easy if you are familiar with your bashrc file! This will entirely use just your .bashrc file and takes 2 seconds to accomplish.
(I use Arch Linux Manjaro so I use .bashrc located in my home directory)
The code to be placed in your .bashrc file:
# Simple bashrc method to launch anything in terminal from any directory
YOURCOMMAND () {
cd /path/to/directory/containing/your/script/ && ./YOURSCRIPT
}
As you can see, first you use the simple 'cd' command and give it the directory of the scripts location, then use '&&' so that you can make the next command executed right after, and finally open your script just as you would normally! Super easy and saved right in your .bash file! :)
Hope I've helped someone!
Sincerely,
AnonymousX
On using bash shell, write that script as function and then put it to the .bashrc or source the file which containing that function by "source file_name"
Now execute the script by function call in the shell.
Either saving it in /usr/bin (or any other directory present in PATH) or editing PATH to include the directory you saved it in will basically make it run in any directory.
from the working directory of 'script.sh'" mv [script.sh] /usr/local/bin"( not tested but seems to be the least complex way IMO.)
You should put it in the global executable directory on your machine. I think that would usually be /usr/bin on Unix-based operating systems (this would however most often require super user privileges on that machine).
You could also put it in any other directory that is in the $PATH environment variable, although it would only work for those users who have that directory in that variable.
You can find the value of $PATH by typing echo $PATH in a shell. The directories are separated by :.
if my windows path looks like this:
c:\ruby\bin;c:\cygwin\bin
then when i go into cgywin and enter "ruby" it will execute the ruby from c:\ruby\bin, failing to find the ruby installed in my cygwin. I have to exclude that path so cygwin would execute the one from /usr/bin.
But i need those 2 paths, since i want to run ruby in windows too.
Anyway to have cygwin have its own path and not inherit those in windows?
thanks.
Add an entry into your .profile to set the path to whatever you want it to be in cygwin.
In cygwin run the command:
$ <favourite text editor eg vi> ~/.profile
Then set the PATH environment variable to whatever you want it to be e.g.:
export PATH=/cygdrive/c/cygwin/bin
NOTE I can't remember whether you can use the c:... version of the path, but if you issue the env command you will see what it should be.