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 |
-n | operand non zero length | 1 |
-z | operand has zero length | 1 |
-d | there exists a directory whose name is operand | 1 |
-f | there exists a file whose name is operand | 1 |
-eq | the operands are integers and they are equal | 2 |
-neq | the opposite of -eq | 2 |
= | the operands are equal (as strings) | 2 |
!= | opposite of = | 2 |
-lt | operand1 is strictly less than operand2 (both operands should be integers) | 2 |
-gt | operand1 is strictly greater than operand2 (both operands should be integers) | 2 |
-ge | operand1 is greater than or equal to operand2 (both operands should be integers) | 2 |
-le | operand1 is less than or equal to operand2 (both operands should be integers) | 2 |