Tuesday, November 16, 2010

Basic shell scripting questions

Tuesday, November 16, 2010
1. How do you find out what’s your shell? – echo $SHELL


2. What’s the command to find out today’s date? – date

3. What’s the command to find out users on the system? – who

4. How do you find out the current directory you’re in? – pwd

5. How do you remove a file? – rm

6. How do you remove a – rm -rf

7. How do you find out your own username? – whoami

8. How do you send a mail message to somebody? – mail somebody@techinterviews.com -s ‘Your subject’ -c ‘cc@techinterviews.com

9. How do you count words, lines and characters in a file? – wc

10. How do you search for a string inside a given file? – grep string filename

11. How do you search for a string inside a directory? – grep string *

12. How do you search for a string in a directory with the subdirectories recursed? – grep -r string *

13. What are PIDs? – They are process IDs given to processes. A PID can vary from 0 to 65535.

14. How do you list currently running process? – ps

15. How do you stop a process? – kill pid

16. How do you find out about all running processes? – ps -ag

17. How do you stop all the processes, except the shell window? – kill 0

18. How do you fire a process in the background? – ./process-name &

19. How do you refer to the arguments passed to a shell script? – $1, $2 and so on. $0 is your script name.

20. What’s the conditional statement in shell scripting? – if {condition} then … fi

21. How do you do number comparison in shell scripts? – -eq, -ne, -lt, -le, -gt, -ge

22. How do you test for file properties in shell scripts? – -s filename tells you if the file is not empty, -f filename tells you whether the argument is a file, and not a directory, -d filename tests if the argument is a directory, and not a file, -w filename tests for writeability, -r filename tests for readability, -x filename tests for executability

23. How do you do Boolean logic operators in shell scripting? – ! tests for logical not, -a tests for logical and, and -o tests for logical or.

24. How do you find out the number of arguments passed to the shell script? – $#

25. What’s a way to do multilevel if-else’s in shell scripting? – if {condition} then {statement} elif {condition} {statement} fi

26. How do you write a for loop in shell? – for {variable name} in {list} do {statement} done

27. How do you write a while loop in shell? – while {condition} do {statement} done

28. How does a case statement look in shell scripts? – case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac

29. How do you read keyboard input in shell scripts? – read {variable-name}

30. How do you define a function in a shell script? – function-name() { #some code here return }

31. How does getopts command work? – The parameters to your script can be passed as -n 15 -x 20. Inside the script, you can iterate through the getopts array as while getopts n:x option, and the variable $option contains the value of the entered option.

19 comments:

Anonymous said...

[url=http://dcxvssh.com]ZyogrCuxUsZ[/url] - NlgGxXBlcoi , http://hhmgziigpu.com

Anonymous said...

Hi! This is my first visit to your blog! We are a

team of volunteers and starting a new initiative in a community in the same niche.
Your blog

provided us valuable information to work on. You have done a

wonderful job!
Also visit my web page www.televisionspain.Net

Anonymous said...

I used to be more than happy to seek out this web-site.

I needed to thanks to your time for this

excellent learn!! I positively having fun with
every

little little bit of it and I have you bookmarked
to check out new stuff you blog post.
My homepage :: www.jobsinspain.org

Anonymous said...

I know this if off topic but I'm looking into starting my own weblog and was curious what all is

required to get setup? I'm assuming having a blog like yours would cost a pretty penny?
I'm not very

internet savvy so I'm not 100% positive. Any recommendations or advice

would be greatly appreciated. Appreciate it
Also visit my blog ... sergings

Anonymous said...

Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your


website? My blog is in the exact same niche

as yours and my visitors would really benefit from some
of

the information you present here. Please let me know if this ok with you.
Many thanks!
My web blog vestigia

Anonymous said...

Wonderful goods from you, man. I've understand your stuff previous to and

you're just too great. I actually like what

you've acquired here, really like what you are stating and the way in which you

say it. You make it entertaining and you still care for to keep it sensible. I

cant wait to read much more from you. This is really a

tremendous site.
Here is my homepage :: http://mickiyjd.xanga.com

Anonymous said...

Hi there, I ԁo bеlieve уour ωеbsite coulԁ bе hаvіng internet broωser cоmpatibilitу issues.
Whеn Ӏ loοk at your website in Safari, it looks fine howeѵer,
when opening in I.E., it's got some overlapping issues. I just wanted to give you a quick heads up! Besides that, fantastic blog!

Here is my homepage: http://www.3dwebdisplay.com/

Anonymous said...

You cаn also buy bundlе deals, which moѕt radio
statіonѕ offer, tο dеcrеаsе the oνerаll ad
cοst. While the effectѕ of antenna
polarіzation may be interpretеd as a reduction in the quality of some radіo linκs, sоme гadio dеsigneгs oftеn makе use of this
property to tune an antеnna to their neеԁs bу restriсting transmiѕsiοn or reсeptіοn to signalѕ on a limited number of vectоrs.
It is a more reliable choіce ωhen compareԁ to traditional concгеte or wooden baгriers
for several reasоnѕ.

Cheсk оut my web site visit the following website page

Anonymous said...

I have been exploring for a bit for any high-quality articles or blog posts in this kind
of house . Exploring in Yahoo I at last stumbled upon this site.
Reading this information So i'm happy to express that I've an incredibly just right uncanny feeling I
discovered just what I needed. I so much unquestionably will make certain
to do not put out of your mind this website and provides it
a glance on a constant basis.

Visit my page cigarette smoking somehow

Anonymous said...

Paragraph writing is also a fun, if you know then you can
write if not it is complicated to write.

Here is my web page :: salesman seo

Anonymous said...

Therefore, the characters must sell animal skins in order to get money for buying the weapons.
'The tears of mankind have not washed away man's desire to kill.

''. I don't want an strange voice to order me around. These applications are delivered with a lot more flexibility at a fraction of the cost compared to desktop applications. "What have you Googled lately. In 2005, the QI Group acquired a UK-based independent telecommunications provider with a strong background in providing advanced communications solutions and technology in the United Kingdom. In fact the publicly owned Ecopetrol has seen an immense FDI surge in the past few years and in spite of being overvalued to some, the stock still is a good bet due to the growth potential it has. * You're
realistic about what you expect from others. Therefore, you cannot afford to miss this incredible
shooter game involving a series of killings.

Here is my web blog: Ashoka courses: Personal profile: Tonia Mccollum

Anonymous said...

There are many different kinds of tools and techniques required to deliver an exceptional SEO India results.
If the executives promise high traffic then understand you are talking with
a non-SEO person. The race is becoming even more challenging with the passing of each day.

Naturally, they will flock to your competitor who does.
Organic SEO uses valid and safe techniques to rank your site for its keyword.
Meta Name and Meta Description Tags are two of
the important ones. Identify your niche audience and be an active member on the forums and blogs.
Having realized that it is practically not possible to combat with SEO
Next in terms of services and offerings at this point of time,
rivals have started thinking of an easier alternative of being successful in their mission.
Online research is required to determine the packages and SEO Company.
Be sure that the SEO outsourcing company you hire is capable of communicating properly.
Arrange the H1, H2 and H3 tags serially with
proper hierarchy. However, in general, SEO services involve using
standard and compliant coding. Their success is based on how many sales and customers you bring.

Such services also include some research that will need
to be done so they can apply this research on major keyword.
For this reason, having mentions from these sites have increasingly become
a more valuable asset for your internet marketing. A well-formed
internal linking structure and good sitemap can ensure all pages
of a website being indexed by a search engine. Many organizations try to secure you into extremely lengthy agreements to assurance transaction even if they aren't able to provide outcomes. However with passing time the complexity in this field has increased and performing an SEO task is not a simple thing to do. A good web solutions company will always provide you realistic time frame for the results to show up. com is one of the premier portals on the World Wide Web which has been formulated with the intention of providing SEO Hosting options for webmasters around the world who seek a way to ensure that their websites reach the top ranks of all major search engines.

Feel free to surf to my web-site :: http://www.medbase.org.ua/

Anonymous said...

Wow, this post is pleasant, my younger sister is analyzing such
things, therefore I am going to tell her.

Feel free to surf to my weblog ... atlaslm.com

Anonymous said...

hi!,I love your writing so so much! percentage
we keep in touch more about your post on AOL? I need a specialist on this space to unravel my problem.
Maybe that is you! Having a look ahead to look you.


my web-site ... rar password cracker

Anonymous said...

Saved as a favorite, I like your site!

Feel free to visit my blog post Suggested Internet site

Anonymous said...

I am extremely inspired together with your writing talents and also with the
structure in your weblog. Is that this a paid subject matter or did you customize it your
self? Either way stay up the nice high quality writing, it is uncommon to look a great
blog like this one these days..

Have a look at my blog post - http://kayjewelersengagementrings.net/Types-of-fashion-trends-for-Women-clothing-styles/

Anonymous said...

It's going to be end of mine day, except before finish I am reading this impressive article to improve my experience.

Visit my weblog - how can you get free gems in dragonvale

Chennai Hot Model said...

Enjoy the most amazing escort service with Chennai Escorts
Independent Escorts in Chennai

Mikethomson said...

I am definitely enjoying your website. You definitely have some great insight and great stories. Lahore escorts