Bash & Shell Scripting (50 Qs)•Part 3: Advanced Text Processing & Production Internals (Senior / Lead)
What is the `eval` command and why is it considered dangerous?
senior Levelbash-shellAdvanced Text Processing
In Simple Words:
eval string parses and evaluates string arguments as executable shell commands:
- Security Vulnerability: If untrusted user input is passed to
eval, an attacker can inject arbitrary commands (eval "ls $user_input"whereuser_input="; rm -rf /"). - Almost always replaceable with Arrays, Parameter Expansion, or Indirect Variable References (
${!var}).