Infosys Shell Scripting Technical Interview Questions and Answers
When preparing for an Infosys technical interview, many candidates focus only on programming languages and database concepts. However, Shell Scripting is equally important, especially if you’re interviewing for roles that involve system administration, DevOps, automation, or working in Linux/Unix environments.
Shell scripting interview questions in Infosys are designed to test your ability to automate tasks, manage files, handle processes, and write efficient scripts. Below, I’ve compiled a complete set of Infosys Shell Scripting interview questions with detailed answers that will help you revise before the big day.
1. Basic Shell Scripting Questions
Q1. What is a shell?
A shell is a command-line interpreter that allows users to interact with the operating system. It takes input commands, executes them, and returns the output. Common shells include Bash, Korn shell, and Z shell.
Q2. What is shell scripting?
Shell scripting is the process of writing a series of commands in a file (script) that can be executed together. It helps in automating repetitive tasks like backups, log monitoring, and file management.
Q3. What are some commonly used shells in Linux/Unix?
-
Bash (Bourne Again Shell)
-
sh (Bourne Shell)
-
csh (C Shell)
-
ksh (Korn Shell)
-
zsh (Z Shell)
Q4. How do you write and execute a shell script?
-
Open a file, e.g.,
script.sh
. -
Start with a shebang line:
#!/bin/bash
-
Write your commands.
-
Save the file and give execute permission:
chmod +x script.sh ./script.sh
Q5. What is the difference between shell and bash?
-
Shell is a general term for command interpreters.
-
Bash is a specific shell (Bourne Again Shell), widely used in Linux.
2. Intermediate Shell Scripting Questions
Q6. What are positional parameters in shell scripting?
Positional parameters allow you to pass arguments to a script.
-
$0
→ Script name -
$1, $2, …
→ Arguments -
$#
→ Number of arguments -
$@
→ All arguments
Example:
#!/bin/bash
echo "First argument: $1"
echo "Second argument: $2"
Q7. How do you take user input in a shell script?
Using the read
command:
echo "Enter your name:"
read name
echo "Hello $name"
Q8. Difference between =
and ==
in shell scripting?
-
In test conditions (
[ ]
),=
is used for string comparison. -
In [[ ]], both
=
and==
can be used for strings, but==
supports pattern matching.
Q9. What is the difference between >
and >>
?
-
>
overwrites a file with new content. -
>>
appends content to the file.
Q10. How do you check file types and permissions in a script?
if [ -f file.txt ]; then
echo "It is a file"
fi
if [ -r file.txt ]; then
echo "File has read permission"
fi
3. Advanced Shell Scripting Questions
Q11. How do you handle loops in shell scripting?
For Loop Example:
for i in 1 2 3 4 5
do
echo "Number $i"
done
While Loop Example:
count=1
while [ $count -le 5 ]
do
echo "Count is $count"
count=$((count+1))
done
Q12. What are exit statuses in shell scripting?
-
0
→ Command executed successfully. -
Non-zero → Error occurred.
We can check exit status using$?
.
Example:
ls /wrongpath
echo "Exit status: $?"
Q13. How do you schedule scripts in Unix/Linux?
Using cron
jobs.
-
Run
crontab -e
. -
Add entry:
0 2 * * * /home/user/backup.sh
(Runs backup.sh at 2 AM daily)
Q14. How do you debug a shell script?
Run the script with -x
option:
bash -x script.sh
This prints each command before executing.
Q15. How do you handle functions in shell scripting?
Functions help reuse code. Example:
greet() {
echo "Hello, $1"
}
greet "Infosys"
4. Real-World Shell Scripting Questions (Infosys Focused)
Q16. Write a script to find the largest of three numbers.
#!/bin/bash
echo "Enter three numbers:"
read a b c
if [ $a -ge $b ] && [ $a -ge $c ]; then
echo "$a is largest"
elif [ $b -ge $a ] && [ $b -ge $c ]; then
echo "$b is largest"
else
echo "$c is largest"
fi
Q17. Write a script to count lines, words, and characters in a file.
#!/bin/bash
echo "Enter filename:"
read file
wc $file
Q18. How do you check system memory and CPU usage with a script?
#!/bin/bash
echo "Memory Usage:"
free -h
echo "CPU Usage:"
top -bn1 | grep "Cpu(s)"
Q19. How can you monitor a log file in real-time?
Use tail -f
command. Example:
tail -f /var/log/syslog
Q20. What’s the best way to secure a shell script?
-
Use proper file permissions (
chmod 700 script.sh
). -
Avoid storing plain text passwords.
-
Validate all inputs.
-
Use logging and error handling.
Final Thoughts
Infosys shell scripting interview questions are not just about syntax. They test whether you can think like a problem-solver — automating a manual process, debugging errors, or scheduling jobs efficiently. If you prepare with a mix of theory, syntax, and small real-world scripts, you’ll be able to handle any question with confidence.
For Infosys aspirants, my advice is: practice writing small automation scripts daily — even simple tasks like renaming files, creating backups, or monitoring processes. This will give you practical confidence and an edge in the interview.
Tags: Infosys Shell Scripting Technical Interview Questions And Answers