How to preserve a shell variable data until shutdown? The 2019 Stack Overflow Developer Survey Results Are In Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Community Moderator Election ResultsFastest way to get list of all file sizesHow to get data shown out of workspace or directly from application?How do I create a service for a shell script so I can start and stop it like a daemon?Finding change in shared object through bashHow to use tee command with echo as per below requirement?Extracting values from a text file having | pipe as a delimiter in text file using awk command and Replacing new lines with <br> tag using sed?Redirect stdout and/or stderr to path in variableBash: add column and write variable, varying per lineWriting a AWK script by taking the input file as an argumentHow to write a shell script using terminal?
Match Roman Numerals
Why doesn't shell automatically fix "useless use of cat"?
Student Loan from years ago pops up and is taking my salary
Single author papers against my advisor's will?
What other Star Trek series did the main TNG cast show up in?
Can I visit the Trinity College (Cambridge) library and see some of their rare books
Using dividends to reduce short term capital gains?
Keeping a retro style to sci-fi spaceships?
How to handle characters who are more educated than the author?
Accepted by European university, rejected by all American ones I applied to? Possible reasons?
Make it rain characters
How to determine omitted units in a publication
Solving overdetermined system by QR decomposition
Is this wall load bearing? Blueprints and photos attached
Can each chord in a progression create its own key?
How to support a colleague who finds meetings extremely tiring?
Is 'stolen' appropriate word?
How do you keep chess fun when your opponent constantly beats you?
Intergalactic human space ship encounters another ship, character gets shunted off beyond known universe, reality starts collapsing
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
The following signatures were invalid: EXPKEYSIG 1397BC53640DB551
Simulating Exploding Dice
Does Parliament need to approve the new Brexit delay to 31 October 2019?
How to read αἱμύλιος or when to aspirate
How to preserve a shell variable data until shutdown?
The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Community Moderator Election ResultsFastest way to get list of all file sizesHow to get data shown out of workspace or directly from application?How do I create a service for a shell script so I can start and stop it like a daemon?Finding change in shared object through bashHow to use tee command with echo as per below requirement?Extracting values from a text file having | pipe as a delimiter in text file using awk command and Replacing new lines with <br> tag using sed?Redirect stdout and/or stderr to path in variableBash: add column and write variable, varying per lineWriting a AWK script by taking the input file as an argumentHow to write a shell script using terminal?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
The shell variable is created by a script. It needs to be retained even after closing terminal and launching another script and accessing it.
I don't want to write to a file(in HDD). If it possible to write the content of variable in file(that is stored exclusively in RAM), how can it be done?
The data needs to be changed frequently, so I don't want to do so much I/O operations to Hard disk.
linux shell-script files ram
add a comment |
The shell variable is created by a script. It needs to be retained even after closing terminal and launching another script and accessing it.
I don't want to write to a file(in HDD). If it possible to write the content of variable in file(that is stored exclusively in RAM), how can it be done?
The data needs to be changed frequently, so I don't want to do so much I/O operations to Hard disk.
linux shell-script files ram
If your data changes frequently (to the point where your are concerned about the I/O operations for performances), then storing it in an "enhanced" environment variable is probably not a good solution: the value may change during your shells life. Meanwhile, if you still want to go that route and store the data in memory, you can create a tmpfs device, mount it and use it as a regular HDD to store a file with the value.
– Zeitounator
Apr 9 at 6:37
You could also look intotmpfs, a filesystem that exists in-memory and backed by swap space.
– Haxiel
Apr 9 at 9:59
add a comment |
The shell variable is created by a script. It needs to be retained even after closing terminal and launching another script and accessing it.
I don't want to write to a file(in HDD). If it possible to write the content of variable in file(that is stored exclusively in RAM), how can it be done?
The data needs to be changed frequently, so I don't want to do so much I/O operations to Hard disk.
linux shell-script files ram
The shell variable is created by a script. It needs to be retained even after closing terminal and launching another script and accessing it.
I don't want to write to a file(in HDD). If it possible to write the content of variable in file(that is stored exclusively in RAM), how can it be done?
The data needs to be changed frequently, so I don't want to do so much I/O operations to Hard disk.
linux shell-script files ram
linux shell-script files ram
asked Apr 9 at 4:02
Prakash BhattaraiPrakash Bhattarai
11
11
If your data changes frequently (to the point where your are concerned about the I/O operations for performances), then storing it in an "enhanced" environment variable is probably not a good solution: the value may change during your shells life. Meanwhile, if you still want to go that route and store the data in memory, you can create a tmpfs device, mount it and use it as a regular HDD to store a file with the value.
– Zeitounator
Apr 9 at 6:37
You could also look intotmpfs, a filesystem that exists in-memory and backed by swap space.
– Haxiel
Apr 9 at 9:59
add a comment |
If your data changes frequently (to the point where your are concerned about the I/O operations for performances), then storing it in an "enhanced" environment variable is probably not a good solution: the value may change during your shells life. Meanwhile, if you still want to go that route and store the data in memory, you can create a tmpfs device, mount it and use it as a regular HDD to store a file with the value.
– Zeitounator
Apr 9 at 6:37
You could also look intotmpfs, a filesystem that exists in-memory and backed by swap space.
– Haxiel
Apr 9 at 9:59
If your data changes frequently (to the point where your are concerned about the I/O operations for performances), then storing it in an "enhanced" environment variable is probably not a good solution: the value may change during your shells life. Meanwhile, if you still want to go that route and store the data in memory, you can create a tmpfs device, mount it and use it as a regular HDD to store a file with the value.
– Zeitounator
Apr 9 at 6:37
If your data changes frequently (to the point where your are concerned about the I/O operations for performances), then storing it in an "enhanced" environment variable is probably not a good solution: the value may change during your shells life. Meanwhile, if you still want to go that route and store the data in memory, you can create a tmpfs device, mount it and use it as a regular HDD to store a file with the value.
– Zeitounator
Apr 9 at 6:37
You could also look into
tmpfs, a filesystem that exists in-memory and backed by swap space.– Haxiel
Apr 9 at 9:59
You could also look into
tmpfs, a filesystem that exists in-memory and backed by swap space.– Haxiel
Apr 9 at 9:59
add a comment |
3 Answers
3
active
oldest
votes
A variable set in one environment cannot be accessed in parent or other (non-child) shells. The following will work:
export my_variable="testing..."
bash
echo $my_variable
But $my_variable will not be accessible in another terminal, unless you put these lines in some file (e.g. .bashrc or a file executable by .bashrc)
Another option is to use fish shell...
fish -c "set -u my_variable 'testing...'"
You can read more here
From the fish documentation
-U or --universal causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell.
Not sure what exactly is your requirement, but just out of curiosity: if you are concerned about the contents of the variable being accessible / readable, you can write the data to a file and set the permissions to --x------ and put the file in .bashrc.
I think yourfishexample needs a bit more explanation as it's not clear how that would help.
– Kusalananda♦
Apr 9 at 6:47
add a comment |
To survive reboots and close of terminal you need to write the variable value in file. You can write it on this way (for example)
echo "$VAR" >/path/to/file
You can restore it on this way (for example)
VAR="`cat /path/to/file`"
And you need to store it in file on every change of value
add a comment |
1) Get/Generate some C/Shell code/program to echo/cout it's PID.
2) Name that file, call it "whatever" and compile/chmod +x "whatever"
3) ./allocate $("./whatever --name='$(plugin)' ")
And that should do it.
[P.S] This needs to reference its own self in memory. It is possible, break out of the shell
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511365%2fhow-to-preserve-a-shell-variable-data-until-shutdown%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
A variable set in one environment cannot be accessed in parent or other (non-child) shells. The following will work:
export my_variable="testing..."
bash
echo $my_variable
But $my_variable will not be accessible in another terminal, unless you put these lines in some file (e.g. .bashrc or a file executable by .bashrc)
Another option is to use fish shell...
fish -c "set -u my_variable 'testing...'"
You can read more here
From the fish documentation
-U or --universal causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell.
Not sure what exactly is your requirement, but just out of curiosity: if you are concerned about the contents of the variable being accessible / readable, you can write the data to a file and set the permissions to --x------ and put the file in .bashrc.
I think yourfishexample needs a bit more explanation as it's not clear how that would help.
– Kusalananda♦
Apr 9 at 6:47
add a comment |
A variable set in one environment cannot be accessed in parent or other (non-child) shells. The following will work:
export my_variable="testing..."
bash
echo $my_variable
But $my_variable will not be accessible in another terminal, unless you put these lines in some file (e.g. .bashrc or a file executable by .bashrc)
Another option is to use fish shell...
fish -c "set -u my_variable 'testing...'"
You can read more here
From the fish documentation
-U or --universal causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell.
Not sure what exactly is your requirement, but just out of curiosity: if you are concerned about the contents of the variable being accessible / readable, you can write the data to a file and set the permissions to --x------ and put the file in .bashrc.
I think yourfishexample needs a bit more explanation as it's not clear how that would help.
– Kusalananda♦
Apr 9 at 6:47
add a comment |
A variable set in one environment cannot be accessed in parent or other (non-child) shells. The following will work:
export my_variable="testing..."
bash
echo $my_variable
But $my_variable will not be accessible in another terminal, unless you put these lines in some file (e.g. .bashrc or a file executable by .bashrc)
Another option is to use fish shell...
fish -c "set -u my_variable 'testing...'"
You can read more here
From the fish documentation
-U or --universal causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell.
Not sure what exactly is your requirement, but just out of curiosity: if you are concerned about the contents of the variable being accessible / readable, you can write the data to a file and set the permissions to --x------ and put the file in .bashrc.
A variable set in one environment cannot be accessed in parent or other (non-child) shells. The following will work:
export my_variable="testing..."
bash
echo $my_variable
But $my_variable will not be accessible in another terminal, unless you put these lines in some file (e.g. .bashrc or a file executable by .bashrc)
Another option is to use fish shell...
fish -c "set -u my_variable 'testing...'"
You can read more here
From the fish documentation
-U or --universal causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell.
Not sure what exactly is your requirement, but just out of curiosity: if you are concerned about the contents of the variable being accessible / readable, you can write the data to a file and set the permissions to --x------ and put the file in .bashrc.
edited Apr 9 at 6:56
answered Apr 9 at 6:16
Mike V.D.C.Mike V.D.C.
1747
1747
I think yourfishexample needs a bit more explanation as it's not clear how that would help.
– Kusalananda♦
Apr 9 at 6:47
add a comment |
I think yourfishexample needs a bit more explanation as it's not clear how that would help.
– Kusalananda♦
Apr 9 at 6:47
I think your
fish example needs a bit more explanation as it's not clear how that would help.– Kusalananda♦
Apr 9 at 6:47
I think your
fish example needs a bit more explanation as it's not clear how that would help.– Kusalananda♦
Apr 9 at 6:47
add a comment |
To survive reboots and close of terminal you need to write the variable value in file. You can write it on this way (for example)
echo "$VAR" >/path/to/file
You can restore it on this way (for example)
VAR="`cat /path/to/file`"
And you need to store it in file on every change of value
add a comment |
To survive reboots and close of terminal you need to write the variable value in file. You can write it on this way (for example)
echo "$VAR" >/path/to/file
You can restore it on this way (for example)
VAR="`cat /path/to/file`"
And you need to store it in file on every change of value
add a comment |
To survive reboots and close of terminal you need to write the variable value in file. You can write it on this way (for example)
echo "$VAR" >/path/to/file
You can restore it on this way (for example)
VAR="`cat /path/to/file`"
And you need to store it in file on every change of value
To survive reboots and close of terminal you need to write the variable value in file. You can write it on this way (for example)
echo "$VAR" >/path/to/file
You can restore it on this way (for example)
VAR="`cat /path/to/file`"
And you need to store it in file on every change of value
answered Apr 9 at 4:09
Romeo NinovRomeo Ninov
7,00732129
7,00732129
add a comment |
add a comment |
1) Get/Generate some C/Shell code/program to echo/cout it's PID.
2) Name that file, call it "whatever" and compile/chmod +x "whatever"
3) ./allocate $("./whatever --name='$(plugin)' ")
And that should do it.
[P.S] This needs to reference its own self in memory. It is possible, break out of the shell
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
1) Get/Generate some C/Shell code/program to echo/cout it's PID.
2) Name that file, call it "whatever" and compile/chmod +x "whatever"
3) ./allocate $("./whatever --name='$(plugin)' ")
And that should do it.
[P.S] This needs to reference its own self in memory. It is possible, break out of the shell
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
1) Get/Generate some C/Shell code/program to echo/cout it's PID.
2) Name that file, call it "whatever" and compile/chmod +x "whatever"
3) ./allocate $("./whatever --name='$(plugin)' ")
And that should do it.
[P.S] This needs to reference its own self in memory. It is possible, break out of the shell
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1) Get/Generate some C/Shell code/program to echo/cout it's PID.
2) Name that file, call it "whatever" and compile/chmod +x "whatever"
3) ./allocate $("./whatever --name='$(plugin)' ")
And that should do it.
[P.S] This needs to reference its own self in memory. It is possible, break out of the shell
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Apr 9 at 7:26
JoeJoe
1195
1195
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511365%2fhow-to-preserve-a-shell-variable-data-until-shutdown%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If your data changes frequently (to the point where your are concerned about the I/O operations for performances), then storing it in an "enhanced" environment variable is probably not a good solution: the value may change during your shells life. Meanwhile, if you still want to go that route and store the data in memory, you can create a tmpfs device, mount it and use it as a regular HDD to store a file with the value.
– Zeitounator
Apr 9 at 6:37
You could also look into
tmpfs, a filesystem that exists in-memory and backed by swap space.– Haxiel
Apr 9 at 9:59