How do you pass arguments to a shell script?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

Arguments are passed after the script name: ./script.sh arg1 arg2 arg3. Inside the script, access them via positional parameters: $1 is the first argument, $2 second, etc. $0 is the script name itself. $# is the count of arguments. $@ is all arguments as separate words (preserves quoting when quoted: "$@"). $* is all arguments as a single word. Always use "$@" (quoted) when passing arguments to another command to handle arguments with spaces correctly. Use shift to shift positional parameters left. getopts handles option parsing (-f value style flags).

Pro Tip

Back up your answer with a specific project or situation. Saying 'In my last Linux / Shell Scripting project, I used this when...' immediately makes your answer more credible and memorable.