sorry i should have made it clear,i tried row=str(row) but environment variableisnot set
It is set, but, as it would happen for any other language (bash
included), you are modifying environment variables of the current process, so it's normal that, if you come back to the shell, the change is not visible (it would be visible, instead, to processes started from your script, since environment variables are normally copied to child processes).
You cannot overcome this restriction; as explained in several other answers, it's not possible to set environment variables of the parent process. Period.
What people normally do is to source
a shell script to set the environment directly in the shell - the script runs under the current shell and thus modifies its environment variables. This of course can work only for the shell language.
Another alternative that some programs use (see e.g. ssh-agent
) is to print on the standard output a short shell script that sets the appropriate variables:
matteo@teokubuntu:~$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-xkn6jGSZAxoA/agent.5184; export SSH_AUTH_SOCK;
SSH_AGENT_PID=5185; export SSH_AGENT_PID;
echo Agent pid 5185;
The program, then, is intended to be used as eval $(programname)
, which runs programname
's output in the current shell.