Getting Rid of Having to Write to Flat Files

Ok,

so i've been having to write to flat files lately and then making my script read information from the flat file and then work off of that.

i dont want to keep doing that because i believe it creates a mess. i like to keep my work all to one script instead of having that one script create temp files.

so, is there there a way to write the informationn that would have been written to a flat file to the memory and work off the memory as if it were a flat file?

you can use variables???

how do you make the variable recognizable or retrievable or accessible throughout the script? can you give an example?

assign the value to a variable and you can retreive by adding '$' at the begining of the variable name like the example below. incase, if you want to make it accessible from different processes then you can export the variable like the 2nd example.

Example 1: Variable=XXXXX
echo $Variable
Example 2:export Variable=XXXXX
echo $Variable

Perfect. thanks. the second example is what I think i needed.

---------- Post updated at 12:01 PM ---------- Previous update was at 11:40 AM ----------

what happens if I wanted to add to the contents of the $Variable, like i would be able to do if i were to write to a flat file? is that possible?

variable=XXXXX
echo $variable
XXXXX
variable="$variable YYYYY"
echo $variable
XXXXX YYYYY

Only comment is about passing variables to children processes. you can pass them as arguments on the command line or use:

export variable

the child process will pick it up.
You need to keep in mind some limitations of variables.
Particularly things like:

var1='<file1'

this variable will store it, but when using it in a straight forward way it will not work.

sed $var1

does not do what is expected

to make it work on eneds to use eval command

eval sed $var1

will work as expected

there are several different ways to do this.

1: If it is discrete pieces of data like names, addresses or whatever, you can use a "sqlite" database. No engine needed, just the libraries and one database file. You'll need to know SQL of course.

2: If you're worried about leaving a mess, keep a variable with a list of the file names in it, like $TMPFILES, then at the end, just rm $TMPFILES. Another thing you can do is use $$ to create them. e.g. TMP1=/tmp/$$.tmp

You can use variables if you're not dealing with tons and tons of data.