#!/bin/bash #Program: #User inputs his first name and last name.Program shows his full name. #History: #2020/10/10 sam First release PATH=/bin:/sbin:/user/bin:/user/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH read -p "Please input your first name:" firstname read -p "Please input your last name: " lastname echo -e "\nYour full name is:$firstname $lastname" [root@localhost myshellscript]# chmod u+x sh02.sh [root@localhost myshellscript]# ls sh01.sh sh02.sh [root@localhost myshellscript]# ./sh02.sh Please input your first name:Yuan Please input your last name: Qiong Your full name is:Yuan Qiong [root@localhost myshellscript]#
时间: 2024-02-05 07:02:40 浏览: 84
这是一个简单的 Shell 脚本,它会提示用户输入名字和姓氏,然后将它们拼接起来并输出用户的全名。脚本中用到了 read 命令来读取用户的输入,用 echo 命令来输出结果。通过 chmod 命令将脚本设置为可执行文件,然后通过 ./sh02.sh 命令来执行脚本。执行结果显示了用户输入的名字和姓氏以及拼接后的全名。
阅读全文