太激动了太激动了!!!!
时隔半个多月我终于学完shell语法了,当自己写的脚本运行完作业是一百分之后真的太激动了
![](https://i-blog.csdnimg.cn/blog_migrate/abcdd93bbcdd129e1009a6fb8775b592.png)
附完成的全部脚本代码:
! /bin/bash
#******** homework 0 *************
dir_0=/home/acs/homework/lesson_1/homework_0
homework 1 create 0
for i in dir_a dir_b dir_c
do
mkdir $dir_0/$i
done
#******** homework 1 ****************
homework 1 create 1
dir_1=/home/acs/homework/lesson_1/homework_1
for i in a.txt b.txt c.txt
do
cp $dir_1/$i $dir_1/${i}.bak
done
#******** homework 2 ****************
dir_2=/home/acs/homework/lesson_1/homework_2
homework 1 create 2
for i in a b c
do
mv ${dir_2}/${i}.txt ${dir_2}/${i}_new.txt
done
#******* homework 3 *****************
dir_3=/home/acs/homework/lesson_1/homework_3
homework 1 create 3
for i in a.txt b.txt c.txt
do
mv ${dir_3}/dir_a/$i ${dir_3}/dir_b
done
#******* homework 4 *****************
homework 1 create 4
dir_4=/home/acs/homework/lesson_1/homework_4
rm ${dir_4}/*.txt
#******* homework 5 *****************
homework 1 create 5
dir_5=/home/acs/homework/lesson_1/homework_5
rm ${dir_5}/* -r
#******* homework 6 *****************
homework 1 create 6
dir_6=/home/acs/homework/lesson_1/homework_6
mv ${dir_6}/task.txt ${dir_6}/done.txt
mkdir ${dir_6}/dir_a
mv ${dir_6}/done.txt ${dir_6}/dir_a/
#******* homework 7 *****************
homework 1 create 7
dir_7=/home/acs/homework/lesson_1/homework_7
for i in {0..2}
do
mkdir ${dir_7}/dir_${i}
for j in a b c
do
cp ${dir_7}/${j}.txt ${dir_7}/dir_${i}/${j}${i}.txt
done
done
#******* homework 8 *****************
homework 1 create 8
dir_8=/home/acs/homework/lesson_1/homework_8
rm ${dir_8}/dir_a/a.txt
mv ${dir_8}/dir_b/b.txt ${dir_8}/dir_b/b_new.txt
cp ${dir_8}/dir_c/c.txt ${dir_8}/dir_c/c.txt.bak
#******* homework 9 *****************
homework 1 create 9
dir_9=/home/acs/homework/lesson_1/homework_9
rm ${dir_9}/*.txt
homework 1 test