ex43.sh

来自「Shall高级编程」· Shell 代码 · 共 32 行

SH
32
字号
#!/bin/bash# Exercising "eval" ...y=`eval ls -l`  #  Similar to y=`ls -l`echo $y         #+ but linefeeds removed because "echoed" variable is unquoted.echoecho "$y"       #  Linefeeds preserved when variable is quoted.echo; echoy=`eval df`     #  Similar to y=`df`echo $y         #+ but linefeeds removed.#  When LF's not preserved, it may make it easier to parse output,#+ using utilities such as "awk".echoecho "==========================================================="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=3echo Major: $major, minor: $minor   #  Major: 3, minor: 4

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?