Linux Interview Questions: Set 1

Pravallika DPravallika D
2 min read
  • What is Bash?

    • Bash (Bourne Again Shell) is a command-line interpreter and scripting language used in Unix-based operating systems. It is an improved version of the Bourne Shell (sh).
  • How do you create a Bash script?

    • Create a file with a .sh extension, add the shebang #!/bin/bash at the top, write commands, and give it execute permissions using chmod +x script.sh.
  • What is the significance of #!/bin/bash?

    • It tells the system to use Bash as the interpreter for executing the script.
  • How do you execute a Bash script?

  • What are positional parameters in Bash?

    • $0 (script name), $1, $2, etc., represent arguments passed to the script. $# gives the count of arguments.
  • How do you take user input in Bash?

    • Using the read command:

        read -p "Enter your name: " name
        echo "Hello, $name"
      
  • What is the difference between $@ and $*?

    • Both represent all script arguments, but $@ treats them as separate strings, while $* treats them as a single string.
  • How do you define and use variables in Bash?

    • Assign: name="P"

    • Access: echo $name

    • Variables are case-sensitive.

  • What is a here document (HEREDOC)?

    • A way to pass multi-line input to a command:

        cat <<EOF
        This is a multi-line
        string in a script.
        EOF
      
  • How do you check if a file exists in Bash?

    • Using -e flag:

        if [ -e file.txt ]; then
            echo "File exists"
        else
            echo "File does not exist"
        fi
      
0
Subscribe to my newsletter

Read articles from Pravallika D directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pravallika D
Pravallika D

Hi, I’m Pravallika. I'm a DevOps Engineer with over 3 years of experience in Azure, Git, Kubernetes, Terraform, Docker, and CI/CD pipelines. I share real-world DevOps experiences, debugging insights, and interview tips to help navigate challenges. Passionate about automation, problem-solving, and continuous learning—let’s grow together!