Ok so I saw at work a script which is on OpenVMS using the DCL scripting language that they have a way to do a catch all for warnings or errors etc...  There is a page about it here.  basically its ON warning THEN GOTO sendfailemail or something like that. I was wondering without using a bunch of if statements is there a way to do such a thing in bash?  I am looking for something that can do a trap not just based on ERR but return code. What is nice about vms is that you can do on warning which on vms is exit status 0 vs error which is exit status 2. So I know I can do trap ... ERR but I wanted something that could trap exit status 1 or 2 specifically.
What is your favorite method to handle errors in Bash?  The best example of handling errors I have found on the web was written by William Shotts, Jr at .   He suggests using the following function for error handling in Bash:  #!/bin/bash  # A slicker error handling routine  # I put a variable in my scripts named PROGNAME which # holds the name of the program being run.  You can get this # value from the first item on the command line ($0).  # Reference: This was copied from &lt;http://www.linuxcommand.org/wss0150.php&gt;  PROGNAME=$(basename $0)  function error_exit {  #   ---------------------------------------------------------------- #   Function for exit due to fatal program error #       Accepts 1 argument: #           string containing descriptive error message #   ----------------------------------------------------------------       echo "${PROGNAME}: ${1:-"Unknown Error"}" 1&gt;&amp;2     exit 1 }  # Example call of the error_exit function.  Note the inclusion # of the LINENO environment variable.  It contains the current # line number.  echo "Example of error with line number and message" error_exit "$LINENO: An error has occurred."   Do you have a better error handling routine that you use in Bash scripts?
Limit of function of hyperbolic Is it possible to create an instance of a generic type in Java? I'm thinking based on what I've seen that the answer is no (due to type erasure), but I'd be interested if anyone can see something I'm missing:  class SomeContainer&lt;E&gt; {     E createContents()     {         return what???     } }   EDIT: It turns out that  could be used to resolve my issue, but it requires a lot of reflection-based code, as some of the answers below have indicated.  I'll leave this open for a little while to see if anyone comes up with anything dramatically different than Ian Robertson's . How to connect an LED indicator to a circuit? I would like to know how can i add a safety switch with an LED indicator to a circuit , so that if the safety switch is on then the LED lights , and when i want to use the device , all what i have to do is to press the normally-open switch.   I have attached this schematic and im not sure if it will work correctly  ,as i am a very beginner in electronics   Thanks How to change Power button shutdown action to run a script under systemd What does "Warning: untrusted X11 forwarding setup failed: xauth key data not generated" mean when ssh'ing with -X? There is a button in the "basic math assistant" which wraps highlighted text in chosen brackets. Is there no keyboard command for this? Linux Command Not Functioning As Alias If we pick randomly two points inside a circle centred at $O$ with radius $R$, and draw two circles centred at the two points with radius equal to the distance between them, what is the expected area of the intersection of the two cirlces that contain the origin $O$. What is $\arctan(x) + \arctan(y)$ I know $$g(x) = \arctan(x)+\arctan(y) = \arctan\left(\frac{x+y}{1-xy}\right)$$  which follows from the formula for $\tan(x+y)$. But my question is that my book defines it to be domain specific, by which I mean, has different definitions for different domains:  $$g(x) = \begin{cases}\arctan\left(\dfrac{x+y}{1-xy}\right), &amp;xy &lt; 1 \\[1.5ex]  \pi + \arctan\left(\dfrac{x+y}{1-xy}\right), &amp;x&gt;0,\; y&gt;0,\; xy&gt;1 \\[1.5ex]  -\pi + \arctan\left(\dfrac{x+y}{1-xy}\right), &amp;x&lt;0,\; y&lt;0,\; xy &gt; 1\end{cases}$$  Furthermore, When I plot the function $2\arctan(x)$, it turns out that the book definition is correct. I don't understand how such peculier definition emerges. Thank you. I'd like to create a Categorized style in QGIS, classify with it data in a shapefile and then save the shapefile with the new categorized style. Is it possible? I'm having the same problem as it was questioned   I can't get throught the step where I need to show that $\nabla_{E_i}E_j (p)=0$. It only leads to $$ \nabla_{E_i}E_j(p)=\sum_{lk}^n a_{il}(0)\dfrac{\partial b_jk}{\partial x_l}(0)\partial x_k(p) $$ which I can't show that equals zero.  On the linked question, there is also the indication that $\nabla_{E_i}E_j (E_k)=\Gamma^k_{ij}$. This could lead that $\nabla_{E_i}E_j (E_k)(p)=\Gamma^k_{ij}(p)=0$, but $\nabla_{E_i}E_j (E_k)(p)$ is not equal to $\nabla_{E_i}E_j (p)$ which is the one I need.  Can someone help me? How do I resize my current ubuntu partition? I've got Ubuntu 10.10 installed to use my whole hard-disk, but would like to use the 130GB of free space I've got to create a new partition and do some development on Unity and Natty.  Can I use gparted to do this?  If so how? Prior to doing some benchmarking work how would one free up the memory (RAM) that the Linux Kernel is consuming for its buffers and cache?    Note that this is mostly useful for benchmarking. Emptying the buffers and cache reduces performance! If you're here because you thought that freeing buffers and cache was a positive thing, go and read . The short story: free memory is unused memory is wasted memory. Make mouse left-handed and touchpad right-handed I see that I can configure mouse and touchpad all in one panel (Ubuntu 13.10, defaults, Gnome). Which is to some extend. Namely, I want to have the touchpad differently configured then the mouse and ...  When I have an (USB) mouse attached I use it normally left-handed. Therefore I switch the buttons to left-handed. But when I use the touchpad I feel little bit lost with that kind of configuration. Therefore I wanna have it right-handed.  Is there a way to achieve the following: when I plugin a mouse (respectively when it is detected) automatically switch to left-handed and when I unplug it, switch automatically to right-handed? I have a PC with an OEM install of Win 8 updated to 8.1.  It has 3 physical hard drives in it.  The drive where Windows is installed has a LOT of partitions on it already.    Can I install Ubuntu on a different physical hard drive than Windows, and be able to dual-boot?  I am able to boot to a live USB of Ubuntu 14.04, so I think I'm about ready to proceed.  But if I can make my installation easier by using a different physical drive, I'd like to do that. Overstayed in the Philippines for years: How to go back to the US without paying a big fine? I'm a U.S. Citizen and I have been overstaying in the Philippines for 5 years. I want to go back to U.S what's the penalty?   I don't have enough money to pay a big fine, is there a way to avoid that? There's a spaceship, nearing the end of its journey. Everybody on board is in cryosleep. For some reason the wake-up system malfunctions, and the ship will fly on indefinitely. The people at the space port realise this, and try to wake someone up. Their last resort is finding someone on board who is telepathic, and wake this person up. They find one, but it turns out to be an unborn baby. Difference between confidence intervals and prediction intervals For a prediction interval in linear regression you still use $\hat{E}[Y|x] = \hat{\beta_0}+\hat{\beta}_{1}x$ to generate the interval. You also use this to generate a confidence interval of $E[Y|x_0]$. What's the difference between the two? I am designing a hobby project that will run on a battery so I am trying to reduce power consumption. The SoC I am using has the ability to go into a deep sleep mode where it consumes very little power, and then can be interrupted by a falling edge on a pin.  I want to generate a high-low-high pulse when the state of a reed switch changes in either direction. I have been reading a lot and it seems that a one-shot monostable circuit can be built from a couple of transistors and an RC circuit to generate an output pulse when an edge is detected. I understand how that works. However, I can't figure out the best way to also pulse on the opposite edge.  One thought, was to just combine two one-shots that are configured to trigger on rising and falling edges respectively, and use the transistors at the output to pull the common pull-up low (kind of like a NOR gate).  Since I am a hobbyist, I am mostly using passive components. What is the "real" way of doing this in a low-power configuration using logic devices?  Edit: I figure I should mention something about the timing requirements. Normally the reed switch will be either open or closed for many seconds at minimum before changing states.  Edit: Here is an example of the circuit I was using for detecting only the falling edge:    And here is the ~20ms pulse it was producing for ~200ms button press simulating the reed switch (Channel 1 is Vbe for T1 and Channel 2 is measured at RST): Novel where pyramids "grow" and change Earth's magnetic field? I read this in (most likely) the 1980s or 1990s. The protagonists found what they believed were alien spacecraft; over time, they &quot;morphed&quot; into Mesoamerican-style pyramids (stepped, not smooth like Egyptian pyramids). Each time they &quot;grew&quot;, an area where electrical equipment either failed or was unreliable grew; the pyramid itself became a new magnetic pole. It turned out that there were a dozen of these objects, spaced to cover the entire world from the corners of an icosahedron; the final morph of the pyramids caused the fields of electrical &quot;disablement&quot; to cover the entire world.