Bash & Shell Scripting (50 Qs)•Part 3: Advanced Text Processing & Production Internals (Senior / Lead)
Security in Bash: Preventing command injection (`eval` risks) and safe variable quoting rules.
senior LevelSecurity & Auth
In Simple Words:
- Never use
evalwith user input:eval "cmd $user_input"allows an attacker to pass; rm -rf /or$(malicious_command). - Always Quote Variables: Use
"$VAR"instead of$VAR. Unquoted variables undergo word splitting and globbing, turning a file named*.*ormy file.txtinto multiple dangerous arguments. - Use
printf %q: Sanitizes and safely escapes arbitrary strings for reuse in shell commands.