<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shell Programming Job Interview Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/shell-programming-job-interview/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/shell-programming-job-interview/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 27 Feb 2021 09:53:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Interview Questions &#038; Answer Sets : Shell Programming</title>
		<link>https://www.scmgalaxy.com/tutorials/interview-questions-answer-sets-shell-programming/</link>
					<comments>https://www.scmgalaxy.com/tutorials/interview-questions-answer-sets-shell-programming/#respond</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Fri, 16 Apr 2010 00:00:00 +0000</pubDate>
				<category><![CDATA[Interview Questions & Answers]]></category>
		<category><![CDATA[Answer]]></category>
		<category><![CDATA[Interview]]></category>
		<category><![CDATA[Interview Questions & Answer for Shell Programming]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[Most Asked]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Questions]]></category>
		<category><![CDATA[Selected]]></category>
		<category><![CDATA[Sets]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell Programming]]></category>
		<category><![CDATA[Shell Programming Interview]]></category>
		<category><![CDATA[Shell Programming Interview Guide]]></category>
		<category><![CDATA[Shell Programming Interview Q&A]]></category>
		<category><![CDATA[Shell Programming Interview Questions & Answer]]></category>
		<category><![CDATA[Shell Programming Job Interview]]></category>
		<category><![CDATA[Top]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2010/04/16/interview-questions-answer-sets-shell-programming/</guid>

					<description><![CDATA[<p>Interview Questions Sets : Shell Programming How do you find out what’s your shell? Answer: echo $SHELL What’s the command [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/interview-questions-answer-sets-shell-programming/">Interview Questions &#038; Answer Sets : Shell Programming</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h3><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4281" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2010/04/shell-programming-interview.png" alt="shell-programming-interview" width="600" height="400" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2010/04/shell-programming-interview.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2010/04/shell-programming-interview-300x200.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></h3>
<h3>Interview Questions Sets : Shell Programming</h3>
<p><b>How do you find out what’s your shell? </b><br />
Answer: echo $SHELL</p>
<p><b>What’s the command to find out today’s date? </b><br />
Answer: date</p>
<p><b> What’s the command to find out users on the system? </b><br />
Answer: who</p>
<p><b>How do you find out the current directory you’re in? </b><br />
Answer: pwd</p>
<p><b>How do you remove a file? </b><br />
Answer: rm</p>
<p><b>How do you remove a file?</b><br />
Answer: rm -rf</p>
<p><b>How do you find out your own username? </b><br />
Answer: whoami</p>
<p><b>How do you send a mail message to somebody? </b><br />
Answer: mail somebody@techinterviews.com -s ‘Your subject’ -c ‘cc@techinterviews.com‘</p>
<p><b>How do you count words, lines and characters in a file? </b><br />
Answer: wc</p>
<p><b>How do you search for a string inside a given file? </b><br />
Answer: grep string filename</p>
<p><b>How do you search for a string inside a directory? </b><br />
Answer: grep string *</p>
<p><b>How do you search for a string in a directory with the subdirectories recursed? </b><br />
Answer: grep -r string *</p>
<p><b>What are PIDs? </b><br />
Answer: They are process IDs given to processes. A PID can vary from 0 to 65535.</p>
<p><b>How do you list currently running process? </b><br />
Answer: ps</p>
<p><b>How do you stop a process? </b><br />
Answer: kill pid</p>
<p><b>How do you find out about all running processes? </b><br />
Answer: ps -ag</p>
<p><b>How do you stop all the processes, except the shell window? </b><br />
Answer: kill 0</p>
<p><b>How do you fire a process in the background? </b><br />
Answer: ./process-name &amp;</p>
<p><b>How do you refer to the arguments passed to a shell script? </b><br />
Answer: $1, $2 and so on. $0 is your script name.</p>
<p><b>What’s the conditional statement in shell scripting? </b><br />
Answer: if {condition} then … fi</p>
<p><b>How do you do number comparison in shell scripts? </b><br />
Answer: -eq, -ne, -lt, -le, -gt, -ge</p>
<p><b>How do you test for file properties in shell scripts? </b><br />
Answer: -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</p>
<p><b>How do you do Boolean logic operators in shell scripting? </b><br />
Answer: ! tests for logical not, -a tests for logical and, and -o tests for logical or.</p>
<p><b>How do you find out the number of arguments passed to the shell script? </b><br />
Answer: $#</p>
<p><b>What’s a way to do multilevel if-else’s in shell scripting? </b><br />
Answer: if {condition} then {statement} elif {condition} {statement} fi</p>
<p><b>How do you write a for loop in shell? </b><br />
Answer: for {variable name} in {list} do {statement} done</p>
<p><b>How do you write a while loop in shell? </b><br />
Answer: while {condition} do {statement} done</p>
<p><b>How does a case statement look in shell scripts? </b><br />
Answer: case {variable} in {possible-value-1}) {statement};; {possible-value-2}) {statement};; esac</p>
<p><b>How do you read keyboard input in shell scripts? </b><br />
Answer: read {variable-name}</p>
<p><b>How do you define a function in a shell script? </b><br />
Answer: function-name() { #some code here return }</p>
<p><b>How does getopts command work? </b><br />
Answer: 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.</p>
<p><b>What’s a way to do multilevel if-else’s in shell scripting?</b><br />
Answer: if then elif fi</p>
<p><b>How do you write a for loop in shell? </b><br />
Answer: for in do done</p>
<p><b>How do you write a while loop in shell?</b><br />
Answer: while do done</p>
<p><b>How does a case statement look in shell scripts? </b><br />
Answer: case in ) ;; ) ;; esac</p>
<p><b>How do you define a function in a shell script?</b><br />
Answer: function-name()</p>
<p><b>How do you find out about all running processes?</b><br />
Answer: ps -ag</p>
<p><b>How do you stop a process? </b><br />
Answer: kill pid</p>
<p><b>How do you remove a file?</b><br />
Answer: rm</p>
<p><b>How do you remove recursively?</b><br />
Answer: rm -rf</p>
<p><b>What are PIDs?</b><br />
Answer: They are process IDs given to processes. A PID can vary&#8230;</p>
<p><b>How do you list currently running process?</b><br />
Answer: ps</p>
<p><b>What is $$?</b></p>
<p>What is a named pipe?</p>
<p>What does || mean?</p>
<p>What does &amp;&amp; mean?</p>
<p>What is a loop?</p>
<p>What does while do?</p>
<p>What is a function?</p>
<p><b>What are the different kinds of loops available in shell script?</b><br />
for if while case</p>
<p><b>What does $# stand for?</b></p>
<p>$# returns the number of parameters that are passed to a shell script<br />
$? returns the exit code of the last executed command (0 : Successful, 1 or other: Failed)</p>
<p><b>What does $? return?</b><br />
Will return the status of the command which is executed lastly.<br />
0 &gt; Success<br />
2 &gt; Error</p>
<p><b>How do u open a read only file in Unix?</b><br />
&#8220;vi -R filename&#8221;</p>
<p><b>What is the difference between a shell variable that is exported and the one that is not exported? </b></p>
<p><b>If you have a string &#8220;one two three&#8221;, Which shell command would you use to extract the strings?</b></p>
<p><b>How do you schedule a command to run at 4:00 every morning?</b></p>
<p><b>How will you list only the empty lines in a file (using grep)? </b><br />
grep ^$ filename.txt</p>
<p><b>When you login to a c shell, which script would be run first? (before the terminal is ready for the user) </b></p>
<p>first /etc/.login script is run &amp; after that<br />
~/.login is run &amp; then ~/.cshrc is run.</p>
<p><b>How would you get the character positions 10-20 from a text file? </b><br />
cat filename.txt | cut -c 10-20</p>
<p><b>How would you print just the 25th line in a file (smallest possible script please)?</b><br />
tail -n +25Â | head -1 OR<br />
head -n 25 | tail -1</p>
<p><b>How would you replace the n character in a file with some xyz?</b><br />
sed &#8216;s/n/xyz/g&#8217; filename &gt; new_filename</p>
<p>Grep | SED |</p>
<p>How you will list the ordinary files in your current directory that are not user-writable?</p>
<p>Use Command substitution with grep to list the names of the persons from emp.lst who were born today.</p>
<p>How will you remove blank lines from a file using (i) grep  and (ii) sed?</p>
<p>Locate lines longer than 100 abd smaller than 150 characters using (i) grep  and (ii) sed?</p>
<p>How do you delete all leading and trailing spaces in all lines of a file?</p>
<p><strong>Making Script Interactive</strong><br />
# read name<br />
# echo “$name”</p>
<p><strong>Special Parameters Used by Shell</strong><br />
# $* &#8211; It stores the complete set of positional parameters as a single string<br />
# $? – Exit Status of last command<br />
# $# &#8211; Number of arguments specified in command line<br />
# $0 – Holds the command name itself<br />
# $$ &#8211; PID of current Shell<br />
# $! – PID of last the last Background job</p>
<p><strong>Exit status of command</strong><br />
# exit 0 – Used when everything went fine<br />
# exit 1 – Used when something went wrong</p>
<p>0 indicates the success and other values point to failure</p>
<p><strong>The Logical Operator &amp;&amp; and ||</strong><br />
cmd1 &amp;&amp; cmd2 &#8211; cmd2 is excuted only when cmd1 succeeds.<br />
cmd1 || cmd2 &#8211; cmd2 is excuted only when cmd1 Fails</p>
<p>Usage of –a and -o</p>
<p>The if Conditional<br />
If command is successful<br />
then<br />
execute command<br />
else<br />
execute command<br />
fi</p>
<p>If command is successful<br />
then<br />
execute command<br />
fi</p>
<p>If command is successful<br />
then<br />
execute command<br />
elif command is successful<br />
then<br />
execute command<br />
else<br />
execute command<br />
fi</p>
<p><strong>Using test AND [ ] to evaluate expressions</strong><br />
# test $x –eq $y<br />
# [$x –eq $y]</p>
<p><strong>Numeric Comparison Operators used by test</strong><br />
# -eq – Equal to<br />
# -ne – Not Equal to<br />
# -gt – Greater than<br />
# -ge – Greater than or equal to<br />
# -ge – Less than<br />
# -le – Less than or equal to</p>
<p><strong>String Tests used by test</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="319"><strong>Test</strong></td>
<td valign="top" width="319"><strong>True if</strong></td>
</tr>
<tr>
<td valign="top" width="319"><strong>s1=s2</strong></td>
<td valign="top" width="319">String s1 = s2</td>
</tr>
<tr>
<td valign="top" width="319"><strong>s1 != s2</strong></td>
<td valign="top" width="319">String s1 is not equal to s2</td>
</tr>
<tr>
<td valign="top" width="319"><strong>-n stg</strong></td>
<td valign="top" width="319">String stg is not a null string</td>
</tr>
<tr>
<td valign="top" width="319"><strong>-z stg</strong></td>
<td valign="top" width="319">String stg is a null string</td>
</tr>
<tr>
<td valign="top" width="319"><strong>stg</strong></td>
<td valign="top" width="319">String stg is assigned and not null</td>
</tr>
<tr>
<td valign="top" width="319"><strong>s1 == s2</strong></td>
<td valign="top" width="319">String s1 =s2</td>
</tr>
</tbody>
</table>
<p><strong>File related Tests with test<br />
</strong></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="272"><strong>Test</strong></td>
<td valign="top" width="367"><strong>True if</strong></td>
</tr>
<tr>
<td valign="top" width="272"><strong>-f file</strong></td>
<td valign="top" width="367">file exists and is a regular file</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-r file</strong></td>
<td valign="top" width="367">file exists and is a readable</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-w file</strong></td>
<td valign="top" width="367">file exists and is a writeable</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-x file</strong></td>
<td valign="top" width="367">file exists and is a executable</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-d file</strong></td>
<td valign="top" width="367">file exists and is a dirctory</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-s file</strong></td>
<td valign="top" width="367">file exists and has a size greate than ero</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-e file</strong></td>
<td valign="top" width="367">file exists</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-u file</strong></td>
<td valign="top" width="367">file exists and has  SUID bit set</td>
</tr>
<tr>
<td valign="top" width="272"><strong>-L file</strong></td>
<td valign="top" width="367">file exists and is a Symbolic link</td>
</tr>
</tbody>
</table>
<p><strong>The case CONDITIONAL</strong><br />
read choice<br />
case “$choice” in</p>
<ul>
<li>ls –l ;;</li>
<li>ps –f ;;</li>
<li>date ;;</li>
<li>who ;;</li>
<li>exit ;;</li>
</ul>
<p>*)   echo “Invalid options”<br />
esac</p>
<p><strong>for</strong><br />
for variable in list<br />
do<br />
commands<br />
done</p>
<p>for file in *.htm *.html<br />
do<br />
sed ‘s/strong/STONG/g’ $file &gt;&gt; $$<br />
mv $$ $file<br />
gzip $file<br />
done</p>
<p><strong>while</strong></p>
<p>while consition is true<br />
do<br />
commands<br />
done</p>
<p><strong>basename – Changing Filename Extension</strong><br />
# basename /home/henry/project3/dec2bin.pl<br />
#dec2bin.pl<br />
# basename ux2nd.txt txt<br />
# ux2nd.                              &#8211; txt stripped off</p>
<p><strong>set  AND shift – Manupulating the Positional Parameters</strong><br />
# set 9876 2345 6213<br />
# echo “\$1 is $1, \$2 is $2, \$3 is $3”<br />
# $1 is 9876, $2 is 2346, $3 is 6213</p>
<p># set `date`<br />
# echo $*</p>
<p>Note- set parses its arguments on the delimiters specified in the environment variable IFS which by default is whitespace.</p>
<p><strong>Shift – Shifting arguments left</strong></p>
<p><strong>Maximum number of Bash arguments</strong><br />
On a 32-bit Linux, this is ARGMAX/4-1 (32767). This becomes relevant if the average length of arguments is smaller than 4.<br />
Linux 2.6.23, one argument must not be longer than MAX_ARG_STRLEN (131072).</p>
<p><strong>How to find success/failure status of a command in different shells?</strong><br />
echo $?<br />
<strong>List all the users in Linux</strong><br />
cat /etc/passwd | cut -d&#8221;:&#8221; -f1</p>
<p><strong>How to change the permission of multiple files which has 655 to 755</strong><br />
for myfile in `find . -perm 655`<br />
do<br />
chmod 755 $myfile<br />
done</p>
<p><strong>Shell script to Print only Size and file name using unix command</strong><br />
ls -l | tr -s &#8221; &#8221; &#8221; &#8220;| cut -d &#8221; &#8221; -f5,9</p>
<p><strong>Shell script to read file line by line</strong><br />
<a href="forum/shell-script/shell-script-to-read-file-line-by-line.html">http://www.scmgalaxy.com/forum/shell-script/shell-script-to-read-file-line-by-line.html</a></p>
<p><strong>How do you remove blank line using grep and sed in shell scripting? </strong><br />
# grep -v &#8220;^$&#8221; filename &gt; newfilename<br />
# sed &#8216;/^$/d&#8217; /tmp/data.txt &gt; /tmp/output.txt<br />
# sed &#8216;/^[PRESS TAB]*$/d&#8217; filename</p>
<p><strong>List all the Groups and users in linux</strong><br />
# less /etc/passwd<br />
# less /etc/group</p>
<p><strong>How Do I Find Out CPU is 32bit or 64bit?</strong></p>
<p># grep flags /proc/cpuinfo<br />
# uname</p>
<p><strong>How to gunzip and untar all at once!</strong><br />
gunzip myfile.tar.gz<br />
tar -xvf myfile.tar<br />
into one<br />
tar -zxvf myfile.tar.gz</p>
<p><strong>Another way to kill multiple processes easily is by adding the following two functions to the .bash_profile.</strong><br />
function psgrep ()<br />
{<br />
ps aux | grep &#8220;$1&#8221; | grep -v &#8216;grep&#8217;<br />
}</p>
<p>function psterm ()<br />
{<br />
[ ${#} -eq 0 ] &amp;&amp; echo &#8220;usage: $FUNCNAME STRING&#8221; &amp;&amp; return 0<br />
local pid<br />
pid=$(ps ax | grep &#8220;$1&#8221; | grep -v grep | awk &#8216;{ print $1 }&#8217;)<br />
echo -e &#8220;terminating &#8216;$1&#8217; / process(es):\n$pid&#8221;<br />
kill -SIGTERM $pid<br />
}</p>
<pre>  # psgrep http</pre>
<pre></pre>
<pre>USER       PID %CPU %MEM    VSZ    RSS TTY  STAT START  TIME COMMAND</pre>
<pre>apache   31186       0.0        1.6  23736 17556 ?        S          Jul26       0:40  /usr/local/apache2/bin/httpd</pre>
<pre>apache   31187       0.0        1.3  20640 14444 ?        S          Jul26       0:37  /usr/local/apache2/bin/httpd</pre>
<pre></pre>
<pre># psterm httpd</pre>
<pre></pre>
<pre>terminating 'httpd' / process(es):</pre>
<pre>31186</pre>
<pre>31187</pre>
<pre></pre>
<pre></pre>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/interview-questions-answer-sets-shell-programming/">Interview Questions &#038; Answer Sets : Shell Programming</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/interview-questions-answer-sets-shell-programming/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
