environment variable

Michael F. Stemper michael.stemper at gmail.com
Sat Jun 24 17:14:52 EDT 2017


On 2017-06-24 15:49, Smith wrote:
> Hello to all,
> I wanted to ask you how I could delete a line of an environment variable 
> (PATH)
> 
> ~/Scaricati/pycharm-2017.1.4/bin$ echo $PATH | sed s/:/'\n'/g
> /usr/local/sbin
> /usr/local/bin
> /usr/sbin
> /usr/bin
> /sbin
> /bin
> /usr/games
> /usr/local/games
> /snap/bin
> /path/to/my/program  ---> linea da eliminare
> /home/dbruno/Scaricati/pycharm-2017.1
> 
> Do I unset PATH delete all content?

That would not be a good idea.

Although this seems to be more of a bash question than a python
question, I'll take a crack at it.

The first question is: do you want to eliminate that directory from your
$PATH forever and ever, or do you just want to eliminate it in some
shell instances?

If the first is true, find out where it's being added to your $PATH,
such as ~/.profile or ~/.bashrc and comment out that line.

If the second is true, you could clear it out in real time, with a
little something like:
   . export PATH=`echo $PATH | sed 's,:/path/to/my/program,,'`

This has not been tested, but is reasonably close to what's needed. Note
that you need the period "." at the beginning to make sure that this
happens in the current shell.


> I downloaded pycharm and wanted to make it executable from the command 
> line without accessing the bin folder and launch the bash script:

But, here's the big question. How does having "/path/to/my/program" in
your $PATH variable prevent you from doing that? The simple answer is
that it doesn't.

You might want to ADD something to your $PATH, such as
"~/Scaricati/pycharm-2017.1.4/bin", but taking something out will not
do what you want.

Another approach would be to ADD something to your .bash_aliases file,
such as:

   pych()
   {
     ~/Scaricati/pycharm-2017.1.4/bin/pycharm.sh $*
   }

Then, you can type "pych" at the command line, and bash will interpret
it as the above command, including arguments.

Two words of caution here:
1. I haven't tested this code, either.
3. If pycharm does not know its location (which is not necessarily
    the current directory), it might not be able to find the many
    accessory files that are there.


-- 
Michael F. Stemper
I feel more like I do now than I did when I came in.



More information about the Python-list mailing list