shell中的命令替换

Bash引号的那点事

http://www.igigo.net/archives/category/bash%E9%82%A3%E7%82%B9%E4%BA%8B/page/2、


filelist=`ls -al`
echo $filelist

# put contents of the file into a varible
filecontent=`cat export.txt`
echo $filecontent

# produce a varible from a loop
var1=`for i in 1 2 3 4 5
    do
        echo -n $i # this echo is very important
    done`
echo $var1

i=0
var2=`while [ $i -le 10 ]
    do
        echo -n $i #this echo is very important
        i=$((i+1))
    done`
echo $var2

word_count=$( wc -w $(ls -l | awk '{print $9}') )
echo $word_count

word_count=`wc -w \`ls -l | awk '{print $9}'\``  # 反引号也可以嵌套替换,但是需要通过\进行转意
echo $word_count


©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页