Download Advanced Bash-scripting Guide
Transcript
Advanced Bash-Scripting Guide
26974 pts/3
R+
0:00 ps ax
Each invocation of eval forces a re-evaluation of its arguments.
a='$b'
b='$c'
c=d
echo $a
eval echo $a
eval eval echo $a
#
#
#
#
#
#
$b
First level.
$c
Second level.
d
Third level.
# Thank you, E. Choroba.
Example 15-11. Showing the effect of eval
#!/bin/bash
# Exercising "eval" ...
y=`eval ls -l`
echo $y
echo
echo "$y"
# Similar to y=`ls -l`
#+ but linefeeds removed because "echoed" variable is unquoted.
#
Linefeeds preserved when variable is quoted.
echo; echo
y=`eval df`
echo $y
# Similar to y=`df`
#+ but linefeeds removed.
# When LF's not preserved, it may make it easier to parse output,
#+ using utilities such as "awk".
echo
echo "==========================================================="
echo
eval "`seq 3 | sed -e 's/.*/echo var&=ABCDEFGHIJ/'`"
# var1=ABCDEFGHIJ
# var2=ABCDEFGHIJ
# var3=ABCDEFGHIJ
echo
echo "==========================================================="
echo
# Now, showing how to do something useful with "eval" . . .
# (Thank you, E. Choroba!)
version=3.4
# Can we split the version into major and minor
#+ part in one command?
echo "version = $version"
eval major=${version/./;minor=}
# Replaces '.' in version by ';minor='
# The substitution yields '3; minor=4'
#+ so eval does minor=4, major=3
Chapter 15. Internal Commands and Builtins
195
Related documents
thesisPivot - University of New Mexico
BenchKit - CosyVerif
A Technical History of Apple`s Operating Systems
- HSR - Institutional Repository
Licensing Information User Manual
OpenCL™ Optimization Guide
The Alchemy System for Statistical Relational AI: User Manual
VLBA Pipeline: Outline of Data Reduction Heuristics 1 Introduction
USER`S MANUAL Price Computing Label Scale
CA du 13 novembre 2014 - Le panier de Germaine