Bash “回声”的含义;用法:sysinfo_页面[[-f文件][-i].[-h]]”;

Bash “回声”的含义;用法:sysinfo_页面[[-f文件][-i].[-h]]”;,bash,Bash,我现在正在学习bash。我有点问题。 “file”看起来不像一个变量,而是一个命令 只是无法理解[]中的事情 任何帮助都将不胜感激 这里是原始代码。一些bash脚本 #!/bin/bash # sysinfo_page - A script to produce a system information HTML file ##### Constants TITLE="System Information for $HOSTNAME" RIGHT_NOW=$(date +"%x %r %Z

我现在正在学习bash。我有点问题。 “file”看起来不像一个变量,而是一个命令 只是无法理解[]中的事情 任何帮助都将不胜感激 这里是原始代码。一些bash脚本

#!/bin/bash

# sysinfo_page - A script to produce a system information HTML file

##### Constants

TITLE="System Information for $HOSTNAME"
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"

##### Functions

system_info()
{
    echo "<h2>System release info</h2>"
    echo "<p>Function not yet implemented</p>"

}   # end of system_info


show_uptime()
{
    echo "<h2>System uptime</h2>"
    echo "<pre>"
    uptime
    echo "</pre>"

}   # end of show_uptime


drive_space()
{
    echo "<h2>Filesystem space</h2>"
    echo "<pre>"
    df
    echo "</pre>"

}   # end of drive_space


home_space()
{
    # Only the superuser can get this information

    if [ "$(id -u)" = "0" ]; then
        echo "<h2>Home directory space by user</h2>"
        echo "<pre>"
        echo "Bytes Directory"
        du -s /home/* | sort -nr
        echo "</pre>"
    fi

}   # end of home_space


write_page()
{
    cat <<- _EOF_
    <html>
        <head>
        <title>$TITLE</title>
        </head>
        <body>
        <h1>$TITLE</h1>
        <p>$TIME_STAMP</p>
        $(system_info)
        $(show_uptime)
        $(drive_space)
        $(home_space)
        </body>
    </html>
_EOF_

}

usage()
{
    echo "usage: sysinfo_page [[[-f file ] [-i]] | [-h]]"
}


##### Main

interactive=
filename=~/sysinfo_page.html

while [ "$1" != "" ]; do
    case $1 in
        -f | --file )           shift
                                filename=$1
                                ;;
        -i | --interactive )    interactive=1
                                ;;
        -h | --help )           usage
                                exit
                                ;;
        * )                     usage
                                exit 1
    esac
    shift
done


# Test code to verify command line processing

if [ "$interactive" = "1" ]; then
    echo "interactive is on"
else
    echo "interactive is off"
fi
echo "output file = $filename"


# Write page (comment out until testing is complete)

# write_page > $filename
#/bin/bash
#sysinfo_页面-生成系统信息HTML文件的脚本
#####常数
TITLE=“$HOSTNAME的系统信息”
现在右边=$(日期+%x%r%Z)
TIME\u STAMP=“立即由$USER更新$RIGHT\u”
#####功能
系统信息()
{
echo“系统发布信息”
echo“功能尚未实现

” }#系统结束#信息 显示正常运行时间() { echo“系统正常运行时间” 回声“” 正常运行时间 回声“” }#节目结束#正常运行时间 驱动器空间() { 回显“文件系统空间” 回声“” df 回声“” }#驱动器空间的末端 家庭空间() { #只有超级用户才能获得此信息 如果[“$(id-u)”=“0”];则 echo“按用户显示主目录空间” 回声“” 回显“字节目录” du-s/home/*| sort-nr 回声“” fi }#家庭空间的尽头# 写入第页() { cat
[…]
表示“可选”。
表示“可选”

因此,
[[-f文件][-i]][-h]
分解为:

所有参数都是可选的。如果传递参数,则可以传递
[-f file][-i]
[-h]
中的一个

这种约定的用法有点令人困惑,因为一组
[]
用于分组的次数与用于可选标记的次数一样多。这样一来,内部可选标记就有点不合适了,但仍然是必要的,因为各个参数仍然是可选的

[
  [
    [-f file ]
    [-i]
  ]
  |
  [-h]
]