A
A
Andrey Shiryaev2012-12-14 19:54:12
bash
Andrey Shiryaev, 2012-12-14 19:54:12

Question for those who know a lot about bash scripts

It is required from the bash script to change the value of the variables: PATH and others. Everything seems to work, but it doesn't.

#!/bin/bash

export PATHMY="text"
export PATH="$PATH:/home/myname/test"

I'm doing

echo $PATHMY

Empty, no other variables changed either.

I added the same code to .profile, I log in with a new one and the variables are in place.

How to get changes without logging out?

Ubuntu 11.04 x32

UPD: Perhaps there is a solution in perl or something else - it will not be bad either.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
I
ivnik, 2012-12-14
@ivnik

Run the script like this:

 . ./script.sh

A
astrobeglec, 2012-12-15
@astrobeglec

In the file ~/.bashrc
Add lines:

PATHMY="text"
PATH="$PATH:/home/myname/test"

Each new bash session will use these variables, declare globally - too, but in /etc/bash.bashrc
In the current session, type these commands in the console or remove export from the script.

I
icc, 2012-12-15
@icc

1. Through export, variables are changed only within the framework of this session.
2. Therefore, you need to register in .profile or bash.rc.

L
lnx, 2012-12-14
@lnx

bash -l

P
pomeo, 2012-12-14
@pomeo

:~$ sourcescript.sh

4
4dmonster, 2012-12-15
@4dmonster

but frisky is not so necessary?

PATHMY="text"
export $PATHMY

N
Nikolai Turnaviotov, 2012-12-16
@foxmuldercp

Describe the normal task before you, please. then you can think about how to solve the problem

B
bhavenger, 2013-11-25
@bhavenger

Do not produce unnecessary entities, declare the variable in the script itself:
PATHMY="text"
PATH="$PATHMY:/home/myname/test"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question