日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

shell编程基础之根据输入进行相应的操作

發布時間:2024/4/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 shell编程基础之根据输入进行相应的操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這個題目是

輸入A:創建自己名字的文件夾,如果有這個文件夾的話,就讀取file1和file2的文件內容

輸入B:獲取當前用戶對file1和file2文件權限

輸入C:內容轉為大寫

輸入D:計算連接和文件數目

輸入E:計算文件空行數目

以下是我的代碼:

#! bin/bash read opts; case $opts in 'A') if [ -d ~/li ];thencp ./file1 ~/li;cp ./file2 ~/li;cat ~/li/file1;cat ~/li/file2; elsemkdir ~/li;chmod -R 755 ~/li;fi;; 'B') if [ -d ~/liwei ];thenfile1=$(ls -l ~/li | grep 'file1'| awk -F " " '{print $1}' | cut -d '.' -f 1);file2=$(ls -l ~/li | grep 'file2'| awk -F " " '{print $1}' | cut -d '.' -f 1);echo your power of file1 is $file1;echo your power of file2 is $file2;elseecho please excute 'A' first;fi;; 'C') if [ -d ~/li];thenfile1=$(cat ~/li/file1);file2=$(cat ~/li/file2);upper=$(echo $file1 | tr '[a-z]' '[A-Z]');lower=$(echo $file2 | tr '[a-z]' '[A-Z]');echo 'uppercase show of file1 and file2:';echo $upper;echo $lower;elseecho please excute 'A' first;fi ;; 'D') file_str=$(ls -l /dev | awk -F " " '{print $1}' | cut -c 1 | tr \n , );file_arr=($file_str);l_num=0;d_num=0;for x in ${file_arr[@]}do if [ "$x" = "d" ];thend_num=$(($d_num + 1));fiif [ "$x" = "l" ];thenl_num=$(($l_num + 1));fidoneecho the number of directory in dev is $d_num;echo the number of link in dev is $l_num;;; 'E') line_num=0;test_num=0;if [ -d ~/li ];thenwhile read linedoif [[ ! -n $line ]];thenline_num=$(($line_num + 1));fidone < ~/li/file1echo "the number of blank line is $line_num"; elseecho please excute 'A' first.fi;; esac exit

?

轉載于:https://www.cnblogs.com/rimochiko/p/8168620.html

總結

以上是生活随笔為你收集整理的shell编程基础之根据输入进行相应的操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。