Monday 4 September 2017

Unix Shell Scripting Tutorial - page 7

Unix Shell Scripting Tutorial - page 7

Question: What is meaning of first line in unix?
#!/bin/bash

This indicates that the script should be run in the bash shell regardless of which interactive shell.


Question: What sign is used in unix for comment a line?
Pound Sign

Pound sign (#), is used to comment a line.

# echo "this is comment" 



Question: When to use single quote OR Double quote?
Single quote: When you are assigning string without variable, then you should use single quote.
Double quote: When you are assigning string with variable, then you should use Double quote.


Question: What's wrong in following variable?
strVar = "Hello World! How are you?" 
echo $strVar;

There should not be space before and after the equal sign (=). Correct code are below:
strVar="Hello World! How are you?" 
echo $strVar;



Question: Give sample example of If else?
if condition1
then
 statement1
 statement2
 statement3
 
else
 statement4
 statement5
fi



Question: Give sample example of If elseif?
if condition1
then
 statement1
 statement2
 statement3
 
elif condition2
then
 statement4
 statement5
 
elif condition3
then
 statement6
 statement7
 statement8
fi



Question: Give list of Operator used in unix shell scripting?
Operator Results number of operands
-noperand non zero length1
-zoperand has zero length1
-dthere exists a directory whose name is operand1
-fthere exists a file whose name is operand1
-eqthe operands are integers and they are equal2
-neqthe opposite of -eq2
=the operands are equal (as strings)2
!=opposite of = 2
-ltoperand1 is strictly less than operand2 (both operands should be integers)2
-gtoperand1 is strictly greater than operand2 (both operands should be integers)2
-geoperand1 is greater than or equal to operand2 (both operands should be integers)2
-leoperand1 is less than or equal to operand2 (both operands should be integers)2