#!/bin/bash
#
# 'eval' evaluates (i.e., runs) the argument.
# Very powerful --and very dangerous-- tool to run arbitrary commands.
# Make sure you control the input passed to eval!
#
# Example:

var='ls -l'
eval $var

# Incidentally, you don't need 'eval' for this use-case, and using a string
# is not the best option (better use an array):

cmd_array=(ls -l -a)
cmd_array+=("/etc")      # add more arguments
"$cmd_array[@]"          # execute the array (command + arguments)

# The canonical example is evaluating the output of a command that returns
# commands to be executed.
# One example is 'ssh-agent,' which needs you to set some environmental
# variables in your current shell (a child process cannot do that).
# You must do this:
#
#  eval $(ssh-agent -s)

# Just run it to see its output:

ssh-agent -s

# You will see other applications of 'eval' when running obfuscated
# scripts.
