How do I get my bash script to fail if it's being run as root?

1 Answer

Answer :

#!/bin/bash if [ "$(id -u)" == "0" ]; then echo "This script must not be run as root" 1>&2 exit 1 fi

Related questions

Description : ”Plugged in, not charging” those who using Windows 7 Pro, is anyone is getting this message?

Last Answer : answer:Not here. I am using Windows 7 Pro and am plugged in and charging. No odd messages. I wonder if something went wrong with your battery, adapter or charging circuitry. Good luck getting it resolved.

Description : Tablet without USB port?

Last Answer : No.

Description : Do you purchase your tower computer(s) off the shelf, build it yourself, or have it built for you?

Last Answer : Always custom ordered from Gateway and now Dell. I’ve learned a lot about computers though since my last purchase 3 years ago, so I might try to build the next one instead.

Description : Can you recommend a distance bachelor's degree in software engineering or somesuch?

Last Answer : answer:Drexel University in Philadelphia (I live near Philly so this is my regional opinion) has a very good reputation, at least bricks and mortar Drexel does, having a good computer and technology ... it sounds like online Drexel might actually be a better experience than IRL Drexel. :-)

Description : Can you recommend a business class modem/router?

Last Answer : Buffalo routers with DDWRT is the answer. Do a little research (Google) and get the right one. You won’t look back.

Description : I've got a top of the range gaming PC and am considering selling it - best route?

Last Answer : You might about ½ that if you get lucky and find someone who doesn’t know what they’re doing. 18 months is a Century in Tech Time.

Description : What do I need to know about RAM?

Last Answer : answer:no, you can mix whatever speeds you want (512 with a gig, gig with 2 gig, etc. . . ) you just need to make sure you get the right type of ram (ddr ram, ddr2, sdram, etc) check out crucial.com for more information that’s a simple answer..

Description : Joomla 1.0 or Joomla 1.5?

Last Answer : Whenever I get into a new CMS, I tend to prefer to immerse myself in the older one [especially if the other is a beta], and learn from the documentation. It makes starting afresh with the newest version much easier, and helps me appreciate the changes made.

Description : My aol spyware checker KEEPS popping up with "we have found and detected Estalive" what IS that and how can I get rid of it for good?

Last Answer : AOL is the problem.

Description : The knowledge of diversity factor helps in computing  (1) Plant capacity (2) Average load (3) Units (kWh) generated (4) Peak demand

Last Answer : The knowledge of diversity factor helps in computing Plant capacity

Description : How to fetch files' extension from a variable which contains files & folder list in bash script ?

Last Answer : I know very little about this kind of stuff (very little), but is what you are asking, simply.. what type of file did this information come from? As in, is it a .zip, .exe, .txt, .html, etc… ??

Description : WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip -Web-Development

Last Answer : answer:

Description : Why are people so quick to make it a point to bash wrestling because it's scripted, but they are ok with other TV shows?

Last Answer : Oh no! You mean it isn’t real???!!!

Description : Do you think Zina Bash was sending some nefarious message with her OK sign?

Last Answer : Mosquito bite.

Description : Would you like to join me in New Years party bash?

Last Answer : Some pure Canadian Glacier ice, and some Canadian made Vodka.

Description : So, is it racism if you bash your own race?

Last Answer : answer:Of course it is. I also think people take offense too easily. Anything said with hatred is bad, but making genuine jokes about a race (your own or otherwise) can result in comedy gold. Dave Chappelle is a great example. People should laugh more instead of being insulted by everything.

Description : Can you translate a line of bash into plain english for me?

Last Answer : answer:From Mr. Laureth, who once made a living on the UNIX command line: While I used csh instead of bash, when I did shell scripting, I believe it does this: 1. Pause for 1 second 2. ... collect usernames and passwords of third parties. It's hard to come up with a legitimate reason to do this.

Description : In Ubuntu, how do you create a bash session you can disconnect from and reconnect to remotely without X?

Last Answer : Check screen(1): http://en.wikipedia.org/wiki/Screen_software

Description : If all atheists want is for people to quit pushing there faith on them then why use bumper stickers that specifically bash Christ.

Last Answer : Some atheist (like fundamentalist Christians) believe in letting EVERYONE know about their beliefs. They have bumper stickers, talk about it, go to conventions, and bash what they don't believe in. Atheists, by ... are (or should be) apathetic. They are vocal about their belief in a lack of god.

Description : Are the Clinton haters coming out of the wood work to bash Obama?Where was Gingrich hiding?

Last Answer : Which Clinton? What do they have to gain? Our government (UK) are just as bad, back stabbing when the worlds on it’s knees. These bloody people need shaking. Is there no such thing as being united?

Description : How can I prevent accidental pasting in bash?

Last Answer : bash is old enough that I doubt anyone has put something like that in. Might be something better implemented in the terminal-- are you using a local tty or some sort of remote terminal app?

Description : Is it worthwhile acquiring/learning the bash shell over korn?

Last Answer : I switched to bash a few years ago (from zsh) and have never looked back.

Description : A short circuit in the armature of a DC motor will cause the motor to _____________. A. run fast B. hum when energized C. spark at the brushes D. fail to start

Last Answer : Answer: C

Description : ITunes app store being a fail or is it just me?

Last Answer : Hmm… Sorry, I’m not familiar with gifting apps, but have you read this page? http://support.apple.com/kb/ht2736#4 Scroll to the bottom.

Description : The reason for Rajasthan being deficient in rainfall is: (a) the monsoon fail to reach this area (b) it is too hot (c) there is no water available and thus the winds remain dry (d) the winds do not come across any barrier to cause necessary uplift to be cooled

Last Answer : Ans: (d)

Description : A major problem with complex pricing structures is that they A)fail to generate the level of revenues needed by an organisation. B)confuse customers and lead to customer dissatisfaction. C) ... to regulation by governmental agencies. D)are almost always viewed as being deceptive by customers.

Last Answer : B)confuse customers and lead to customer dissatisfaction.

Description : Can someone read my script and tell me if it's any good?

Last Answer : Go ahead. I’m all ears. PM me, don’t post it as another question.

Description : I need C troubleshooting: When i include a library do i have to do something more in order to have its functions work in my script?

Last Answer : Are you getting any other errors, like “math.h” not found? Actually, IIRC, not finding an include is just a warning…

Description : What are you thoughts going into a movie knowing it’s a reworked Stars Wars script ?

Last Answer : Everything about this will be almost good!

Description : 1. When a ray of light is going from one medium to another, how is its frequency? 2. Who is the author of The Kalam effect: My years with the president ? 3. CENVAT is ... the Relative humidity of the atmosphere directly affected? 20. Kautilya was the Prime Minister of which Indian ruler ?

Last Answer : Answer : 1. Frequency remains same 2. P.M. Nayer 3. Rate of indirect tax 4. 60°S 5. Undeciphered 6. Histology 7. By the Election Commission 8. Sodium carbonate 9. India and Saudi Arabia 10 ... 16. 58th 17. In doing external work 18. 200 19. Change in atmospheric temperature 20. Chandragupta Maurya

Description : The magnitude of sag correction' during measurement of lengths by taping is proportional to the : (a) Cube of the weight of the tape, in kg per m run (b) Cube root of the weight of the tape, in kg per m run ... the tape, in kg per m run (d) Square root of the weight of the tape, in kg per m run

Last Answer : (c) Square of the weight of the tape, in kg per m run

Description : 1. In the short run, a producer,' how long continues his production? 2. Which is the largest mosque in India? 3. Absorption of water by root occurs in the region of which parts? 4. What is the ... when it is nearest to the Sun,? 20. Which was the first fort constructed by the British in India?

Last Answer : Answer : 1. Fixed cost 2. Jama Masjid 3. Root hairs 4. Conduction 5. Chandelles 6. President 7. Tetra-ethyl Lead 8. Pokhran 9. Thermosphere 10. Pallavas 11. The demand exceeds the supply 12. Leaves 13. ... 15. 1510 A.D. 16. Isothermal 17. February 28 18. 1974 19. Perihelion 20. Fort St. George

Description : Lets flip the script: Picky eaters, what one food you CAN get behind?

Last Answer : Fries

Description : Windows script host error, can someone please help?

Last Answer : answer:Your Registry got mangled somehow and messed up your file associations. Given that one of them was .EXE that makes things a little more difficult, though not insurmountable. The simplest fix I ... with the Registry, which will make the necessary changes to get your system back up and running.

Description : Can someone please help me solve this windows 7 script host error?

Last Answer : If you still have the OS disc, I suggest booting into it and see if you can repair the system.

Description : If you could go back in time and make a change to the script of "Back to the Future", what would you change?

Last Answer : When Marty goes into the future, he sees that he is now a washed up actor with Parkinson’s.

Description : How can I make this sort of a ...script, in excel?

Last Answer : You could simply graph them on the same chart. Once the sheet is set up that’s about all that would need to be done. You would not have any fancy transparency though. I would probably just write a small program in Java to do it.

Description : Can I take my written script to another pharmacy and get it filled?

Last Answer : answer:The pharmacy doesn’t care; the insurance company does. If you’re paying out of your own pocket, you’re free to do whatever you want.

Description : What's the best Groupon clone script available?

Last Answer : Gripsell is the best but they are selective in distributing its script licenses. Some other options are Couponic or Wroupon.

Description : Jar Jar Abrams and his entire team of hack writers have been killed by terrorists freedom fighters. You are put in charge of producing the next Star Trek movie. Who will you hire to direct, and who will you hire to write the script?

Last Answer : Warner Herzog. Vince Gilligan

Description : What's bugging my simple JavaScript toggle script?

Last Answer : answer:The toggle_visibility function specifies (eng, met), not (var1, var2), so it seems not to matter what order of parameters you send it, it's going to read (eng, met) always. function toggle_visibility(eng, ... = block'; } else { e1.style.display = block'; e2.style.display = none'; }

Description : Is it possible to reconcile with someone who insists on rewriting the script?

Last Answer : My brother had an issue with one of his daughters . I won't get into it either, but he tried several times to reconcile and she was the same way, she kept coming up with things that had nothing to ... came to him. She didn't exactly apologize or even mention the incident, but he was okay with it.

Description : Economics in the 1920s script?

Last Answer : answer:Use your history research to think of some issue that might have been the cause of conflict at the time-political, social, economic, whatever. Any of those areas would have an ... your script. Include information in their dialogue that shows you know something about the historical context.

Description : How to write a structural analysis of a script?

Last Answer : You should have a good introduction, explaining the environment and the characters.

Description : How can I add an ELSE to this batch script?

Last Answer : answer:Doesn’t ELSE require an IF to go along with it? It’s been a looooong time since I wrote batch scripts, but have you tried: IF tasklist /nh /fi “imagename eq explorer.exe” | find /i “explorer.exe” >nul && ( echo Explorer.exe is running) ELSE (echo Explorer.exe is not running) ??

Description : Can you author a post that contains not a solitary showing of that symbol fifth in rank out of our 26 script-signs (found amidst "d" and "f")?

Last Answer : Oh my God, no. I’m far too lazy for that. On top of which, it would suck up too much of my day.

Description : Why isn't this batch script working?

Last Answer : What’s the shell? Is that windows cmd? Any details to the parse error ? Does “not ask to overwrite” mean don’t overwrite, or you don’t want it to stop and ask you the question?

Description : Help with this batch script?

Last Answer : answer:Try writing this at a DOS prompt and see if it gives you any ideas about how you can format your directory name: echo %date:~10,4%%date:~4,2%%date:~7,2% When I run that it gives me: 20110924 (for ... , then of course you'll need to modify the parsing of the Echo command. I know you can do it.

Description : Simple way to add a GUI to batch script, or similar?

Last Answer : I think you might want to use http://www.horstmuc.de/ui.htm. Enjoy.