写了3个Shell Scripting。麻烦帮忙看看!谢谢!

weixin_38055275 weixin_38055275 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

第一个是:

#!/bin/bash  
echo "a Display disk usage."
echo "b Display file usage for the current directory. "
echo "c Display all executing processes"
read option
echo "$option was been selected"
case $option in
a)
   df
   ;;
b)
   df .
   ;;
c)
   ps -u ced4033
   ;;
*)
esac


意思就是 出现 a b c 三个选项,然后让用户选择,输入a 的话就 显示 空间大小, b 的话就 显示当前目录  c 的话就显示所有exe 文件。
请大家看看我写的是否正确,反正运行没问题!


第二个是:

#!/bin/bash

filename=1
k=1000
until [ $filename = "0" ];do

        echo "Please enter the file name or press 0 to exit!"
        read filename

        if [ -e $filename ]; then
                size=`ls -l $filename | awk '{print $5}'`
              if [ $size = 0 ]; then
                echo "Supplied filename is an empty file"
              else
                echo "Size of supplied file name is $size bytes"
              fi
        else
                echo "Supplied file name does not exits in current directory"
        fi
done

查找文件名,如果文件名不存在,就显示文件不存在,如果存在,就显示文件的大小是 XXBytes, 一直到用户输入 0 才退出。


第三个是:

#!/bin/bash
      

for f in *.txt; do
            base=`basename $f .txt`
            mv $f $base.text
        done

重命名 所有 .txt.文件 为 .text文件。 苜蓿用 for loop。
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部