Is there a way to gracefully handle out-of-memory conditions in a shell script?
$ cat test.sh
#!/bin/sh
i=asdf
while true; do
i="$i $i"
done
$ bash test.sh
test.sh: xrealloc: cannot allocate 18446744072098939008 bytes
Many programming languages allow handling out-of-memory exceptions using simple try-catch constructs. Is it possible to gracefully handle out-of-memory conditions in shell scripts / Bash as well? How?
Would it be possible to either free temporary buffers and attempt to continue execution, or do some custom error handling (save state) and exit with error?