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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人文社科 > 生活经验 >内容正文

生活经验

制作显示欢迎信息的脚本程序

發(fā)布時(shí)間:2023/11/27 生活经验 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 制作显示欢迎信息的脚本程序 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

終端程序恐怕是Linux用戶(hù)使用最為頻繁的了。我的Debian系統(tǒng)啟動(dòng)后便是直接進(jìn)入的終端界面。為了在每次登錄時(shí)或者是在X視窗環(huán)境下打開(kāi)終端程序時(shí)顯示一些歡迎信息,比如當(dāng)前的日期、名人警句等,從而可以增加一些生活情趣,就可以創(chuàng)建一個(gè)腳本程序,然后在~/.bashrc文件調(diào)用它。我自己就寫(xiě)了一個(gè)welcome.sh,執(zhí)行時(shí)首先顯示當(dāng)前登錄的用戶(hù)名與主機(jī)名,然后打印出當(dāng)天的日期、當(dāng)天處于今年的第幾個(gè)星期——這一數(shù)據(jù)在項(xiàng)目匯報(bào)中常被使用。同時(shí),顯示當(dāng)天是今年的第幾天,計(jì)算出距離年末還有幾天,這樣就可以給自己警醒,“又一年即將過(guò)去,自己是否珍惜了時(shí)光?”。最后,腳本調(diào)用fortune程序,隨機(jī)顯示一些警句或有意思的話。將這些綜合起來(lái),寫(xiě)成welcome.sh腳本如下:

#!/bin/bashscript_name="welcome.sh"
script_usage=$(cat <<EOF
welcome.sh [OPTIONS]
EOF
)
script_function=$(cat <<EOF
Display a welcome message.
EOF
)
script_doc=$(cat <<EOF
-h     Display this help.
EOF
)
script_examples=$(cat <<EOF
EOF
)
state_prefix="==="
warning_prefix="***"
error_prefix="!!!"function display_help() {if [ -n "$script_usage" ]; thenecho -e "Usage: $script_usage"fiif [ -n "$script_function" ]; thenecho -e "$script_function"fiif [ -n "$script_doc" ] ; thenecho -e "\n$script_doc"fiif [ -n "$script_examples" ]; thenecho -e "\nExamples"echo -e "$script_examples"fi
}# Delete a same character from the beginning of a variable. The source variable is the global variable $src_string
# $1: pattern character
function del_leading_chars() {local pat_charlocal prev_src_string_lenlocal src_string_lendeclare -i prev_src_string_lendeclare -i src_string_lenpat_char=$1prev_src_string_len=0src_string_len=${#src_string}while [ $(($prev_src_string_len != $src_string_len)) = 1 ]; doprev_src_string_len=$src_string_lensrc_string=${src_string/#${pat_char}/}src_string_len=${#src_string}done
}# Process command options
while getopts ":h" opt; docase $opt inh  )  display_helpexit 0 ;;\? )  display_helpexit 1 ;;esac
done
shift $(($OPTIND - 1))# Start execute the commanddeclare -i total_dates=365
year=`date +%Y`# Test leap year
if [ $(($year % 100 == 0)) = 1 ]; thenif [ $(($year % 400 == 0)) = 1 ]; thentotal_dates=366fi
elseif [ $(($year % 4 == 0)) = 1 ]; thentotal_dates=366fi
fisrc_string=`date +%j`
del_leading_chars '0'
cur_day_no=$src_string
src_string=`date +%V`
del_leading_chars '0'
cur_week_no=$src_stringecho "********************************************************"
echo "Hello "`whoami`"! ""Welcome to "`hostname`"!"
echo "Today is "`date "+%A, %B %d, %Y"`
echo "Week $cur_week_no, day $cur_day_no, remaining days $(($total_dates - $cur_day_no))"
echo "********************************************************"
fortune

welcome.sh放入~/.bashrc后,現(xiàn)在再打開(kāi)終端程序,就會(huì)顯示出現(xiàn)面的信息:

轉(zhuǎn)載于:https://www.cnblogs.com/quantumman/p/4586756.html

總結(jié)

以上是生活随笔為你收集整理的制作显示欢迎信息的脚本程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。