Let's say I want to parse the same log portion several times. I want to do data=$(grep "initial filter" file.log) and do the next filters on $data. Will $data grow until all memory is used up?
2 Answers
It seems there are no limits except whatever is set by the OS:
$ yes=$(yes)
bash: xrealloc: cannot allocate 18446744071562067968 bytes (1617920 bytes allocated)
Oh , your method is wrong, use mktemp such as:
x="$(mktemp)"
grep mohsen /etc/passwd > $x
root@debian:/home/mohsen# echo $x
/tmp/tmp.yuMRWrJbRI
Then at end of your script you can delete your temp file.
At this method instead of variable, you use file.
-
2There's nothing wrong with his method other than potential memory usage. Using this method you now have to worry about securing that file and then cleaning it up. And if
/tmpis a tmpfs mount, and it often is, then it's going to use memory any way.phemmer– phemmer2014-09-24 16:03:50 +00:00Commented Sep 24, 2014 at 16:03