⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex73.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash# Creating a swapfile.ROOT_UID=0         # Root has $UID 0.E_WRONG_USER=65    # Not root?FILE=/swapBLOCKSIZE=1024MINBLOCKS=40SUCCESS=0# This script must be run as root.if [ "$UID" -ne "$ROOT_UID" ]then  echo; echo "You must be root to run this script."; echo  exit $E_WRONG_USERfi    blocks=${1:-$MINBLOCKS}          #  Set to default of 40 blocks,                                 #+ if nothing specified on command line.# This is the equivalent of the command block below.# --------------------------------------------------# if [ -n "$1" ]# then#   blocks=$1# else#   blocks=$MINBLOCKS# fi# --------------------------------------------------if [ "$blocks" -lt $MINBLOCKS ]then  blocks=$MINBLOCKS              # Must be at least 40 blocks long.fi  ######################################################################echo "Creating swap file of size $blocks blocks (KB)."dd if=/dev/zero of=$FILE bs=$BLOCKSIZE count=$blocks  # Zero out file.mkswap $FILE $blocks             # Designate it a swap file.swapon $FILE                     # Activate swap file.#  Note that if one or more of these commands fails,#+ then it could cause nasty problems.#######################################################################  Exercise:#  Rewrite the above block of code so that if it does not execute#+ successfully, then:#    1) an error message is echoed to stderr,#    2) all temporary files are cleaned up, and#    3) the script exits in an orderly fashion with an#+      appropriate error code.echo "Swap file created and activated."exit $SUCCESS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -