#!/bin/bash # This is the first Bash shell program # Scriptname: greetings.sh echo echo -e"Hello $LOGNAME,Ic" echo "it's nice talking to you. echo -n "Your present working directory is: pwd # Show the name of present directory echo echo -e"The time is date +%T!.\nBye' echo
时间: 2024-03-05 14:51:14 浏览: 130
这段代码有几个语法错误,需要修正。下面是修正后的代码:
```
#!/bin/bash
# This is the first Bash shell program
# Scriptname: greetings.sh
echo
echo -e "Hello $LOGNAME,\nIt's nice talking to you."
echo "Your present working directory is: $(pwd)" # Show the name of present directory
echo -e "The time is $(date +%T)!\nBye."
```
这段代码会输出如下内容:
```
Hello username,
It's nice talking to you.
Your present working directory is: /path/to/working/directory
The time is 09:30:00!
Bye.
```
其中,`username` 会被替换为当前用户的用户名,`/path/to/working/directory` 会被替换为当前工作目录的路径,`09:30:00` 会被替换为当前时间。
相关问题
use Linux Write a shell script that displays the value of HOMEPAT H SHLVL, and LOGNAME variables in the following format: HOME= ———————— PATH= ———————— SHLVL= ———————— LOGNAME=————————
Sure, here's a shell script that will display the values of the HOMEPATH, PATH, SHLVL, and LOGNAME variables in the required format:
```
#!/bin/bash
echo "HOME= ${HOMEPATH}"
echo "PATH= ${PATH}"
echo "SHLVL= ${SHLVL}"
echo "LOGNAME= ${LOGNAME}"
```
Save this script with a file extension of `.sh`, and make it executable using the command `chmod +x script_name.sh`. Then, simply run the script using `./script_name.sh` and it will display the values of the specified variables in the required format.
阅读全文