Some details for the Shell which I think is important

  • 拼接字符串, 在定义好变量之后, 输出时候的拼接, 注意无意输出一些空格 。

比如:

#!/bin/bash

a1="China"
a2="${a1}, Japan and Korean are the three important countries in east asia. \n"
a3="Which country do you like the most if you have one chance to travel?"

echo -e $a2$a3 #如果a2到$a3之间插入了空格,那么echo会原样输出空格
#此外,如果想让"\n"输出,而不是输出字符,那么在echo 后面要加-e
  •   String定义后,索引的下标和C一样是从0开始的。
     
     
  • 打印出一个目录下的所有文件
  • 1 for index in $(ls /home/daqing/Share/); do
    2         echo ${index}
    3 done
    4 #在for表达式后面的地址处不是大括号,而是小括号

     

  • 从上一级目录文件夹复制一个文件到此文件夹
  • cp ../b.txt ./ 
    

     

posted @ 2023-06-04 22:43  七块蛋糕  阅读(8)  评论(0编辑  收藏  举报