a.sh
#! /bin/sh export x=/usr/local
we can do source ./a
in command-line. But I need to do the export through shell script.
b.sh
#! /bin/sh . ~/a.sh
no error... but $x
in command-line will show nothing. So it didn't get export.
Any idea how to make it work?
a.sh
#! /bin/sh export x=/usr/local ----------- admin@client: ./a.sh admin@client: echo $x admin@client: <insert ....>
You can use the export command to make local variables global. To make your local shell variables global automatically, export them in your . profile file. Note: Variables can be exported down to child shells but not exported up to parent shells.
To export a environment variable you run the export command while setting the variable. We can view a complete list of exported environment variables by running the export command without any arguments. To view all exported variables in the current shell you use the -p flag with export.
To export the variable in bash, open Terminal from Menu on the bottom left on the screen in your computer system. Click on the Terminal option. Once the terminal is opened, you need to provide a variable, let's call it vech for the sake of ease. We will then assign it a value for now, i.e., “Bus”.
You can put export statements in a shell script and then use the 'source' command to execute it in the current process:
source a.sh
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With