2024年4月12日发(作者:)
例题:
显示日期和时间。
#!/bin/bash
echo “current time is `date`” //date要加反引号
显示文件名,并显示位置参数(执行时带一个参数)。(①$0是一个特殊的
变量,它的内容是当前这个shell程序的文件名;②$1是一个位置参数,位置参数之间用
空格分隔,shell取第一个位置参数替换程序文件中的$1,第二个替换$2,依次类推。)
#!/bin/bash
echo “the program name is $0” //$0是一个特殊的变数
echo “the first para is $1” //$1是一个位置参数
echo “the program exit” //执行时带一个参数 如./ abcd
判断并显示位置参数
#!/bin/bash
if [ -d “$1”];then
echo “$1 is directory ,existed”
else
echo “$1 does not exist ,now create it”
mkdir $1
echo “$1 is created”
fi //执行时带一个参数
问候用户
#!/bin/bash
user=`whoami`
case $user in
teacher)
echo “hello teacher”;;
root)
发布者:admin,转转请注明出处:http://www.yc00.com/web/1712888959a2142212.html
评论列表(0条)