Skip to main content

Structure for Shell and Bashs

Script structure is how a Bash program is organised for reuse: functions, positional arguments, option parsing, and reading input from users, pipes and files. It sits between simple scripts and robust tooling, since well-structured scripts take parameters, return exit codes and read data line by line instead of hardcoding paths.

Stage: Bash Scripting · Part of the Shell and Bash roadmap · Last reviewed 19 November 2026

What to learn in Structure

Structure interview questions

What is the difference between $@ and $*?

Both expand to all positional parameters. When quoted, "$@" keeps each argument as a separate word, preserving spaces inside them, while "$*" joins them into a single string. Use "$@" when forwarding arguments to another command.

How do you read a file line by line safely in Bash?

Use while IFS= read -r line; do ...; done < file. Setting IFS to empty keeps leading and trailing whitespace, and -r stops backslashes from being treated as escapes. Avoid for line in $(cat file), which splits on every space.

Where Structure fits in the Shell and Bash roadmap

Structure belongs to the Bash Scripting stage (beginner level), which takes about 12 hours. Automate.

Back to the full Shell and Bash roadmap