set current directory as environment variable
Hi,
How do you set current directory (full path) in an environment variable? For example your current directory is this: Code:
/home/<user>/downloads/applications/ Code:
export MYHOME=this Hope it would be simple. Prashant |
Hi,
The pwd command shows the current working directory. export CURRENTDIR=`pwd` Hope this helps. |
Doesn't 'export CURRENTDIR=`pwd`;' only work if you are in that directory? Could include it in the users path (not in /etc/profile, /etc/bashrc or any /etc/profile.d/*) but ~/.bashrc (as it's read on interactive and non-interactive shell start):
Code:
[ -d "${HOME}/downloads/applications" ] && PATH=$PATH:${HOME}/downloads/applications |
Thanks drunna,
Now this may be a dumb question but I am new to Linux. I am using this command in a "run.sh" file. Code:
export MYHOME=`pwd` Code:
/home/user/downloads/applications/./run Inside "run.sh", I am setting some vars related to directory structure. For example: Code:
export PYTHONHOME="lib/" Hope I explained well. Prashant |
@unSpawn:
Quote:
But you are correct, it does depends on where it is used (my answer will not work when used in the start-up files mentioned by you). Let's wait and see what the OP really wants :) EDIT Too slow..... OP already replied. /EDIT |
Hi,
If I create a script like this: Code:
#!/bin/bash Quote:
If you want to add the lib/ part you need to tell the script where to add it too: Code:
#!/bin/bash Quote:
|
There's already a variable that holds the present working directory. Oddly enough, it's "$PWD".
|
Hi druuna,
I think you are not getting me. Your script is in "/home/druuna" and when you are executing it from "/data/Downloads", it's printing "/data/Downloads". It has to print "/home/druuna", the directory where "run.sh" resides. Here is the script in "/home/<user>/downloads/application/run.sh" The contents of the script: Code:
export MYHOME=`pwd` Code:
prashant@ubuntucomp:~$ Code:
prashant@ubuntucomp:~$ /home/prashant/downloads/application/./run.sh Code:
/home/prashant Code:
/home/prashant/downloads/application Prashant |
Hi,
In your first post you mentioned this: How do you set current directory (full path) in an environment variable? The current working directory is always seen from where one starts the script (not where the script itself resides). If your script resides in /home/<user>/downloads/application/ and you run it from /home/prashant, the pwd command will print /home/prashant and if you run it from /tmp it will print /tmp. I'm not sure if the /home/<user> part needs to be dynamic in your case (unsure as in: are you asking the correct question). If so you can add the extra part (downloads/application) as mentioned in post #6. If it does not need to be dynamic, but is always /home/prashant/downloads/application you can declare that in one go (export MYHOME=/home/prashant/downloads/application). Dynamic example: Quote:
MYHOME -> holds the current working directory, which is dynamic and depends on where the script is started (/home/druuna in the first example) PYTHONHOME -> holds the content of MYHOME + the added directory, you end up with: /home/druuna/lib Hope this clears things up. |
Quote:
Code:
#!/bin/bash |
Hi colucix,
You are the man!!!!! IT WORKS.... Thanks for the tip. Cheers Prashant |
All times are GMT -5. The time now is 02:19 AM. |