I haven't been able to find the answer to this anywhere and suspect it's not possible. I'd like to know if I can somehow override environment variables set by export MY_VARIABLE="some-value" per directory. Meaning, once I cd into a particular directory where x variable is overridden, anything being run from that directory would see the new value.
Is that possible without expicitly exporting? Perhaps adding some file to the directory like .bashrc or something like that?
Thank you!
Related
If I try to run virtualenv, I get this message:
$ virtualenv
-bash: /Users/me/Library/Python/3.6/bin/virtualenv: No such file or directory
It's not surprising that this happens, because I've removed this directories at an earlier point when trying to clean up my computer from different Python versions. However, how does my system know to look in that directory for virtualenv? I've looked in my bash profile, and there is no mention of virtualenv there.
When you type something your command interpreter has to search the command. Of course it cannot try every possible directory on your system. Then it provides to the user a way to control that process. This is the purpose of the PATH environment variable :
$ echo $PATH
will show you the actual value which looks like dir1:dir2:...:dirn, meaning that commands where searched for in dir1, then dir2, etc. You have to remove the value /Users/me/Library/Python/3.6/bin/ from it. The best way is to edit the .bashrc or .bash_profile file to remove the permanent setting of this variable. Then reconnect.
I have several files with names of mac addresses e.g 50:c7:bf:2f:27:43 I would like to rename these files based on the folder names in the directory
I would like to rename them from 50:c7:bf:2f:27:43 to the folder name that I have already created Phillips
So the final output
Phillips/Philips_1
I believe you are looking for the PWD session-based environment variable:
You might know that, when launching the pwd command, you see the name of the current directory. Well, this is because every time you change directory, the session-based environment variable PWD is modified accordingly: in fact, the command pwd and echo $PWD are exactly the same.
So, in your case, you might do something like:
mv filename "$PWD""_something"
Remark : by session-based environment variable, I mean a variable which looks like an environment variable but which can be different for every session (I don't know the exact term for this).
Using z in zsh, I want to change the default location of where the history is kept.
By default, when your source the shell script
source ~/z/z.sh
It will make a file with the directories you visit in a .z/ directory. While this is fine for most cases, I want to change this to another directory. The README.md does state that you can set some variables for this in my .zshrc
Optionally:
Set $_Z_DATA to change the datafile (default $HOME/.z).
So I added this
export $_Z_DATA="$HOME/.z-history"
But for some reason, I get a warning that my shell can't find the directory.
Any idea why this is happening? Any help is appreciated.
You are having a typo, or haven't yet get how the bash variable works.
You do not need to use $ when declaring a variable. Only when you want to access it.
So just adapt you config with:
export _Z_DATA="$HOME/.z-history"
voilĂ :) it should works
I have two environment variables defined as:
test1=C:\something\dir1
test2=C:\something\dir2
And I'm trying to run the following command:
copy dir1\filename.txt dir2\filename.txt
I know that if I write the copy command with the environment variables it will work, like below:
copy %test1%\filename.txt %test2%\filename.txt
But isn't there a better way to do this? If Windows doesn't find the "dir1" directory in its current directory, won't it try to find it with the system variables it has?
EDIT: Im trying to use the copy command without typing the enviroment variable's name in the command.
Something like "copy dir1\filename.txt dir2\filename.txt", where, if Windows cant find the dir1 directory in its current directory, it would automatically search this directory with the enviroment variables. Is this possible?
This will copy the fully qualified path and filename, and cater for spaces etc.
copy "%test1%\filename.txt" "%test2%\"
If it doesn't work for you then edit your question and give more details about the task.
For mistake I have added a path that I don't want to use.
I have create a file named .base_profile, exported the path using the command source .base_profile, but I don't need this path, how to delete it?
Maybe the title wasn't so appropriate, but I haven't modified the PATH variable.
I have written this in the .base_profile file:
export MP=$MP/usr/local/mysql/bin
And then used the source command.The problem is with the MP variable, which is not one that I want, it's too long.I want to delete it, how to do it?
The way to restore your path to the default is PATH=$(getconf PATH)
Do an
echo $PATH
Then grab with the mouse that part, which looks useful, and append it to:
PATH=
So for example - not on an OSX-System:
PATH=/home/ramy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
If you only sourced the path in one terminal, you can, alternatively, open a new terminal.
If you added the source-command to one configuration script, you have to remove it there, to get rid of it permananetly.
Fix your errors in the file, and fix the env var with
export PATH=[the correct one]