← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Amazon SWE interview, technical phone screen or take-home style question focused on shell scripting. One question, pretty practical, but there's more to it than it looks at first glance.

Questions Asked (1)

Q1

Write a shell script called script.sh that takes a username and a file path as arguments, then prints a single line in the format: <timestamp> <license> <user@hostname>. The username and hostname should be used to build the user@hostname part, the license value should be parsed from the given file, and the script should handle missing arguments, nonexistent files, and permission errors.

System DesignTechnical Trade-offsAPI & Integrations
Author's notes

I thought this was going to be a five-minute thing and then I got stuck on the timestamp format because nobody told me what format to use.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then outline a robust script structure with argument validation, error handling, and parsing logic. Emphasize defensive programming and testability, and discuss trade-offs between simplicity and extensibility.

Pro tip: Use `set -euo pipefail` at the top of the script to catch errors early, and always quote variables to prevent word splitting and globbing issues.

1. Clarify Requirements and Edge Cases

Confirm the exact format, expected license file structure, and how to handle errors (e.g., exit codes, stderr messages). Ask about timestamp format and timezone if not specified.

2. Design Script Structure

Plan the script flow: argument validation, file existence and permission checks, license parsing, and output construction. Consider using functions for modularity.

3. Implement Robust Error Handling

Check for missing arguments, nonexistent files, and permission errors. Use appropriate exit codes and print clear error messages to stderr.

4. Parse License and Build Output

Extract the license value from the file (e.g., using grep/awk/sed), and construct the output line with timestamp, license, and user@hostname.

5. Test and Validate

Mention testing with various inputs: valid file, missing file, no read permission, missing arguments, and different license formats. Use shellcheck for static analysis.

Key Points to Mention

  • Use `set -euo pipefail` for strict error handling.
  • Validate argument count with `$#` and provide usage message.
  • Check file existence with `-f` and readability with `-r`.
  • Parse license robustly (e.g., `grep -oP` or `awk`) and handle parsing failures.
  • Quote variables to avoid word splitting and globbing.
  • Use `date` command for timestamp and `hostname` for hostname.
  • Consider portability (POSIX vs bash) and shebang line.
  • Exit with non-zero status on errors and print to stderr.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.