export of a variable isn't working

Hi

I want export input data ...

echo "month: [ 04 ]"
read m
export m=$m

also

export m

is not working ?
the month-variable should be exportet for the use in other scripts,
but it is not working like this. What i'm doing wrong?

Thanks in advance!
IMPe

echo "month: [ 04 ]"

is not a variable definition. It is just echoing some text.
When you use read , then you have to give it some input.

Example:

$> read m
1234
$> echo $m
1234
$> export m
$> env| grep ^m
m=1234
$> ksh
# echo $m
1234
1 Like

If you read the variabale via another script you have to source that script, something like:

. ./scriptname
1 Like

Hi zaxxon!

Thanks for your answer.
Sorry, my text is quit unclear.
This is the scriptcode ..

echo "month: [ 04 ]"
read m
export m=$m

.. and my input, for example 07 is been taken by read, but i cant export it by this way.
Is there any idea how to do this?

Thanks in advance!
IMPe

do

 
export m

Thanks for your answers, but the export command out of my script is not working. If i set the export m in the console it is working fine.

Replace

export m=$m

with

export m

in your script.

1 Like

i tryed both and both versions are not working

How and where do you test if it is exported? I guess not in the same script. As Franklin already wrote, you have to source the exporting script to have set variables etc. available in your current shell or script.
Just executing the script and after that hoping to have the variable available in the current shell will not work.
The export only works in subsequent shells being called by the shell that exported the variable. It can't be exported that way to a same or higher level shell, if you imagine the calling of shells like a kind of tree construct.

1 Like

Thank you !
Unfortunately i even tried to export the variable to have it available in the current shell.
Thanks, for the explanation!

Perhaps re-read post #3, an additon to the minor correction to the script posted.

How you execute the script is important if you want to set environment variables in the current environment.

That is dot-space-dot-solidus-scriptname.

If such a script exports environment variables those environment variables are available to slave scripts run directly from the current shell. You can never export to a parent script.