[Asus Transformer TF700] elfaure:
2>$1

It combines stdout and stderr into a single output stream I can echo for any non-zero exit codes. I've seen it working for failed umounts during testing?

[Edit] I think I may see the problem. From a previous version, after the error section I use to have an "exit" command that would not only exit the script at that point but apparantly also created the *script* exit code. So if any command line were to error then the script itself as a whole would have a non-zero exit code and that's what I was capturing. I think. Because you are right, it does not work now. When I was rewriting the script I didn't see any need for that exit so I removed it. Or if I am flawed how would I capture the script exit code not the last command exit code?

http://stackoverflow.com/questions/818255/in-the-shell-what-is-21

Here is the code from a previous version where I believe the 2>$1 did echo any non-zero exit code

...
umount $FIREFOX_CACHE_DIR 2>&-

if [ $? != 0 ]; then

echo "***************************************************************************************************"
echo " Script error! Exit code not 0. Did you forget to run as root?"
echo " Or umount failed for an existing mount that was either currently"
echo " in use or did not exist."
echo 2>$1
echo "***************************************************************************************************"

mount | grep _cache
exit

else

echo "***************************************************************************************************"
echo " The script ran successfully! 14 new tmpfs browser mounts created in RAM:"
echo "***************************************************************************************************"
echo

mount | grep _cache

You can see it working here in the umount_all.sh script with identical error trapping (that I just edited and put the exit and grep | mount _cache lines back in) as in the above example from a previous version

u0_a87@android:/ $ su
*** xyzzy 10087 happened ;) ***
u0_a87@android:/ # autostart_fn.sh
***************************************************************************************************
Multi-Browser2RAM startup script. This script must be run as root! This script can also run at boot.

This is a modified fork of Browser2RAM in sh script form. Only browser cache is mapped to RAM.
Browser data is persistent and is not lost after a reboot. Functions with 18 browsers in the stock list.
Users can additionally add more by appending to the browser list.

Created by Emile Faure

Copyright (c) 2013, Emile Faure
All rights reserved.

Acknowledgments/Credits:

GitHub:

Copyright (c) 2013, Steve Niemitz
All rights reserved.

Copyright (c) 2012, Julian Beaumont
All rights reserved.

Special thanks to XDA Developers:

[MENTION=4878287]_that[/MENTION], [MENTION=2446267]becomingx[/MENTION], [MENTION=518363]sbdags[/MENTION], [MENTION=972963]jtrosky[/MENTION], [MENTION=4362404]buhohitr[/MENTION], [MENTION=5117542]Tylorw1[/MENTION]

***************************************************************************************************
Notice: Run this at your own *risk*. We are *not liable* for any damage it may cause.
***************************************************************************************************

***************************************************************************************************
The script ran successfully! All installed browser caches mounted in RAM:
***************************************************************************************************

com.android.browser_cache /data/data/com.android.browser/cache tmpfs rw,relatime,size=51200k 0 0
com.fevdev.nakedbrowser_cache /data/data/com.fevdev.nakedbrowser/cache tmpfs rw,relatime,size=51200k 0 0
com.android.chrome_cache /data/data/com.android.chrome/cache tmpfs rw,relatime,size=51200k 0 0
com.opera.browser_cache /data/data/com.opera.browser/cache tmpfs rw,relatime,size=51200k 0 0
com.opera.mini.android_cache /data/data/com.opera.mini.android/cache tmpfs rw,relatime,size=51200k 0 0
com.tencent.ibibo.mtt_cache /data/data/com.tencent.ibibo.mtt/cache tmpfs rw,relatime,size=51200k 0 0
com.mx.browser_cache /data/data/com.mx.browser/cache tmpfs rw,relatime,size=51200k 0 0
mobi.mgeek.TunnyBrowser_cache /data/data/mobi.mgeek.TunnyBrowser/cache tmpfs rw,relatime,size=51200k 0 0
com.dolphin.browser_cache /data/data/com.dolphin.browser/cache tmpfs rw,relatime,size=51200k 0 0
com.boatbrowser.free_cache /data/data/com.boatbrowser.free/cache tmpfs rw,relatime,size=51200k 0 0
com.boatgo.browser_cache /data/data/com.boatgo.browser/cache tmpfs rw,relatime,size=51200k 0 0
com.baidu.browser.inter_cache /data/data/com.baidu.browser.inter/cache tmpfs rw,relatime,size=51200k 0 0
com.adrenalinebrowser.browser_cache /data/data/com.adrenalinebrowser.browser/cache tmpfs rw,relatime,size=51200k 0 0
gpc.myweb.hinet.net.PopupWeb_cache /data/data/gpc.myweb.hinet.net.PopupWeb/cache tmpfs rw,relatime,size=51200k 0 0
firefox_cache /data/data/org.mozilla.firefox/files/mozilla/4nvh8zhz.default/Cache tmpfs rw,relatime,size=51200k 0 0
u0_a87@android:/ # umount_all.sh
***************************************************************************************************
The script ran successfully! All browser umounts removed from RAM:
***************************************************************************************************

1|u0_a87@android:/ # umount_all.sh
***************************************************************************************************
Script error! Exit code not 0. Did you forget to run as root?
Or umount failed for an existing mount that was either currently
in use or did not exist.
/Removable/MicroSD/Scripts/umount_all.sh[52]: can't create : No such file or directory
***************************************************************************************************
1|u0_a87@android:/ #

I even added an unset to the unmount script just before the exit and it still works the same way as above

#!/system/bin/sh

#REV5
umount /data/data/com.chrome.beta/cache 2>&-
umount /data/data/gpc.myweb.hinet.net.PopupWeb/cache/ 2>&-
umount /data/data/com.uc.browser.hd/cache/ 2>&-
umount /data/data/com.ninesky.browser/cache/ 2>&-

#REV4
#umount /data/data/com.android.launcher 2>&-
#umount /data/data/com.android.systemui 2>&-
umount /data/data/com.opera.browser/cache 2>&-
umount /data/data/com.opera.mini.android/cache 2>&-
umount /data/data/com.mx.browser/cache 2>&-
umount /data/data/com.tencent.ibibo.mtt/cache 2>&-
umount /data/data/com.dolphin.browser/cache 2>&-
umount /data/data/com.baidu.browser.inter/cache 2>&-
umount /data/data/com.adrenalinebrowser.browser/cache 2>&-

#REV3
umount /data/data/com.opera.browser/cache 2>&-
umount /data/data/mobi.mgeek.TunnyBrowser/cache 2>&-
umount /data/data/com.boatbrowser.free/cache 2>&-
umount /data/data/com.boatgo.browser/cache 2>&-

#REV2
umount /data/data/com.android.browser/cache 2>&-
umount /data/data/com.fevdev.nakedbrowser/cache 2>&-
umount /data/data/com.android.chrome/cache 2>&-
FIREFOX_CACHE_DIR="$(ls -d /data/data/org.mozilla.firefox/files/mozilla/*.default/Cache 2>/dev/null)"
umount $FIREFOX_CACHE_DIR 2>&-

if [ $? != 0 ]; then

echo "***************************************************************************************************"
echo " Script error! Exit code not 0. Did you forget to run as root?"
echo " Or umount failed for an existing mount that was either currently"
echo " in use or did not exist."
echo 2>$1
echo "***************************************************************************************************"

unset FIREFOX_CACHE_DIR
mount | grep _cache
exit

else

echo "***************************************************************************************************"
echo " The script ran successfully! All browser umounts removed from RAM:"
echo "***************************************************************************************************"
echo

fi

unset FIREFOX_CACHE_DIR
mount | grep _cache

Ah, your right, but if I put the unset line before the error check it passes. So I am not capturing the script exit code, just the last command executed error code as you clarified. The reason it failed sucessfully above is because the umount line for Firefox failed.

So then, how do I capture the *script* exit code, not the last command exit code?