# homework_0 cd ${path}homework_0/ mkdir dir_{a..c}
# homework_1 cd ${path}homework_1/ for i in {a..c} do cp ${i}.txt ${i}.txt.bak done
# homework_2 cd ${path}homework_2/ for i in {a..c} do mv ${i}.txt ${i}_new.txt done
# homework_3 cd ${path}homework_3/ for i in {a..c} do mv dir_a/${i}.txt dir_b/ done
# honework_4 cd ${path}homework_4/ rm {a..c}.txt
# homework_5 cd ${path}homework_5/ rm dir_{a..c} -r
# homework_6 cd ${path}homework_6/ mkdir dir_a mv "task.txt" "dir_a/done.txt"
# homework_7 cd ${path}homework_7/ mkdir dir_{0..2} for i in {0..2} do for j in {a..c} do cp ${j}.txt dir_${i}/${j}${i}.txt done done
# homework_8 cd ${path}homework_8/ for i in {a..c} do cd dir_${i} if [ ${i} == "a" ] # 注意中括号表达式中每项都要用空格隔开 then rm a.txt elif [ ${i} == "b" ] then mv b.txt b_new.txt elif [ ${i} == "c" ] then cp c.txt c.txt.bak fi cd ../ # 注意循环中的cd命令,在本次循环结束要cd回到上一层 done
# homework_9 cd ${path}homework_9/ rm *.txt # **homework_1** #! /bin/bash
if [ $# -ne 1 ] then echo "arguments not valid" exit 1 elif [ -e "$1" ] then if [ -f "$1" ] #可以简写成 [ -f "$1" ] && echo "regulare file" then echo "regulare file" fi if [ -d "$1" ] then echo "directory" fi if [ -r "$1" ] then echo "readable" fi if [ -w "$1" ] then echo "writable" fi if [ -x "$1" ] then echo "executable" fi exit 0 else echo "not exist" exit 2 fi # **homework_2** #! /bin/bash
dfs() { if [ $1 -eq $((n+1)) ] then ((cnt++)) if [ $cnt == $m ] then local i=1 for ((i = 1;i <= n;i ++)) do echo -e "${path[i]} \c " done echo "" flag=1 fi return 0 fi
local i=1 for (( i = 1;i <= n;i++)) do if [ ${st[i]} -eq 0 ] then st[$i]=1 path[$1]=${i} dfs $(expr $1 + 1) if [ $flag -eq 1 ] then return 0 fi st[$i]=0 fi done }
dfs 1 # **homework_4** #! /bin/bash
read n < "$1" res=0 for ((i = 1;i <= n;i++)) do res=$((res + i * i)) done echo $res > "$2"