I have a bash script that will only work with root privileges, so I want to test whether the user has them.  Other posts (see below) ask and answer how to know whether the user is actually running as root, but not whether the script has root privileges.  These posts say to test whether $EUID is 0.  To try this idea in the context of sudo, I wrote a bash script /tmp/a.sh:  #!/bin/bash echo $EUID   The following two commands were run as a non-root user with sudo privileges on Ubuntu 16.04. If the $EUID suggestion worked in the context of sudo, the second command would have printed 0 instead of a blank line.  $ /tmp/a.sh 1000 $ sudo /tmp/a.sh  $    FYI, an example of the related posts I am referencing is:
I'm writing a simple bash script, but I need it to check whether it's being run as root or not. I know there's probably a very simple way to do that, but I have no idea how.  Just to be clear: What's a simple way to write a script foo.sh, so that the command ./foo.sh outputs 0, and the command sudo ./foo.sh outputs 1?
Why is King Tommen Baratheon the "First of his Name" rather than at least third? How to install latest HPLIP on my Ubuntu to support my HP printer and/or scanner? Let's assume that one has some modern HP printer and/or scanner which is not supported by HPLIP package from official repository. Currently Ubuntu versions have :  trusty (14.04LTS): 3.14.3-0ubuntu3.4 xenial (16.04LTS): 3.16.3+repack0-1 bionic (18.04LTS): 3.17.10+repack0-5 focal (20.04LTS): 3.20.3+dfsg0-2 groovy (20.10): 3.20.5+dfsg0-3build1 hirsute (21.04): 3.21.2+dfsg1-2   What can one do if printer is supported in newer version of HPLIP (checked this in )? What are some examples of induction where the base case is difficult but the inductive step is trivial? According to :     ...proofs by mathematical induction   have two parts: the "base case" that   shows that the theorem is true for a   particular initial value such as n = 0   or n = 1 and then an inductive step   that shows that if the theorem is true   for a certain value of n, it is also   true for the value n + 1. The base   case is often trivial and is   identified as such, although there are   cases where the base case is difficult   but the inductive step is trivial.   What are some examples of proofs by induction where the base case is difficult but the inductive step is trivial? I love making our own bread - we rarely buy shop bought, but it tends to go off very quickly. Part of the appeal is that it doesn't have any "junk" in it - artificial preservatives - which I'm sure contributes to the lovely flavor. Is there anything natural I can add to it to stop it going moldy so fast? Collapsing a stream of multiple lines into one line I have a file containing a a large number of lines, each of which contains a bunch of numbers which are separated by spaces. I process this data in a pipe in some way, and then I want to collapse the multiple lines into a single line of all the numbers separated by spaces.  Is there a standard command-line utility I can use to do this? It seems like most line-by-line utilities won't mess with the newlines... How to label using just numbers from start of text field? In ArcMAP 10.2, I am trying to format the labels on my map.   If the label is   1402 Bowie Road  But  I want only to display numbers:  1402   What is the expression to create this? What is a “protected” or "highly active" question? Questions can be protected (i.e. marked "highly active").   What does it mean for a question to be protected? Why are some questions protected? Who can protect and unprotect questions? Who can answer a protected question? How are protected questions displayed? When should I protect or unprotect a question? When does the Community user protect a question? Variable is already defined in method lambda Pretty much the problem asks if a function is continuous at the point $c$ and $f(c) &gt; 0$ then there exists a $d &gt; 0$ such that $\forall x$, $f(x) &gt; 0$ with $|x-c| &lt; d$.   I can understand what the problem means. That if a function is positive at a point then there is another point that's really close that'll also be positive. I can not prove this in a formal way though. I've tried using the intermediate value theorem and I do not know hot to implement it. Any ideas? This week I saw the definition of a measurable set for an outer measure.     Let $\mu^*$ be an outer measure on a set $X$. We call $A \subseteq X$ measurable if $$\mu^*(E) = \mu^*(A\cap E) + \mu^*(A^c\cap E)$$ for every $E \subseteq X$.   This is not the first time I've seen this definition. Unlike most other things in mathematics, over time I have gained absolutely no intuition as to why this is the definition.   The only explanation I've ever seen is that a set is measurable if it 'breaks up' other sets in the way you'd want. I don't really see why this is the motivation though. One reason I am not comfortable with it is that you require a measurable set to break up sets which, according to this definition, are non-measurable; why would you require that? Of course, you can't say what a non-measurable set is without first defining what it means to be measurable so I suppose no matter what your condition is, it will have to apply to all subsets of $X$.     Is there an intuitive way to think about the definition of measurable sets? Is there a good reason why we should use this definition, aside from "it works"? Getting No module name exifread error from QGIS Photo2Shape plugin? LaTeX figures side by side what is a thyristor As part of my 2330 lv3 am required to know about thyristors. I just want to confirm my understanding is correct. A thyristor is basically similar to a transistor, only it stays switched on when it's trigged for as long as there isn't a break in the circuit it's switching. Am I correct? When to use "If I was" vs. "If I were"? Consider a common proof of the uncountability of $(0,1]$, as presented  for example:  We assume that the reals can be arranged in a sequence $x_k$, represent every number in $x_k$ by its nonterminating decimal expansion, use the diagonal argument to create a sequence of decimal digits that differs from the nonterminating decimal expansion of each number in $x_k$ and then claim that this sequence of digits so generated must be the decimal expansion of some number not in $x_k$.  My problem is with this last step. Could it not be the case that the new sequence of digits is just the terminating decimal expansion of some number already in $x_k$?  Would it not be more correct to use the sequence $x_k$ to generate a sequence of all (both terminating and non-terminating) decimal expansion of all numbers in $[0,1)$ and then apply the diagonal argument? I often see questions on Stack Exchange sites which I presume are written by non-native English speakers who use the word "doubt" in place of the word "question". Is this a case of misunderstanding the correct meaning or are people being taught that this is correct usage? Sufficient Identification for Intra Schengen flights If one takes a direct flight from one Schengen member state to another, what's the minimum sufficient ID that needs to be provided to board the flight? Question regarding an inequality How to prove that $$ \frac{x_1}{1+x_1^2}+\frac{x_2}{1+x_1^2+x_2^2}+\cdots+\frac{x_n}{1+x_1^2+\cdots+x_n^2}&lt;\sqrt{n} $$ knowing that $(x_n)$ is a positive sequence ? I looked up all kinds of inequalities such AM-GM, Chebyshev, Cauchy-Schwarz, but I couldn't manage to obtain anything useful.. Can anyone help ? Cannot delete directory with Directory.Delete(path, true) I'm using .NET 3.5, trying to recursively delete a directory using:  Directory.Delete(myPath, true);   My understanding is that this should throw if files are in use or there is a permissions problem, but otherwise it should delete the directory and all of its contents.  However, I occasionally get this:  System.IO.IOException: The directory is not empty.     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)     at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)     at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)     ...   I'm not surprised that the method sometimes throws, but I'm surprised to get this particular message when recursive is true.  (I know the directory is not empty.)  Is there a reason I'd see this instead of AccessViolationException? Dirac equation as Hamiltonian system Let us consider Dirac equation $$(i\gamma^\mu\partial_\mu -m)\psi ~=~0$$ as a classical field equation. Is it possible to introduce Poisson bracket on the space of spinors $\psi$ in such a way that Dirac equation becomes Hamiltonian equation   $$\dot{\psi}~=~\{ \psi,H\}_{PB}~?$$  Of course, such Poisson bracket would be graded (super Poisson bracket), but if it exists this would explain on classical level why $\frac{1}{2}$-spinors correspond to fermions.