用两种命令分别查看home logname shell
时间: 2023-04-06 08:00:59 浏览: 51
您好,可以使用以下两个命令来查看home、logname和shell:
1. 查看home和logname:echo $HOME 和 echo $LOGNAME
2. 查看shell:echo $SHELL
希望能对您有所帮助。
相关问题
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.
BusyBox v1.29.2 (2022-07-15 02:53:45 UTC) multi-call binary. Usage: su [-lmp] [-] [-s SH] [USER [SCRIPT ARGS / -c 'CMD' ARG0 ARGS]] Run shell under USER (by default, root) -,-l Clear environment, go to home dir, run shell as login shell -p,-m Do not set new $HOME, $SHELL, $USER, $LOGNAME -c CMD Command to pass to 'sh -c' -s SH Shell to use instead of user's default
这是 BusyBox 提供的 su 命令的帮助信息。su 命令可以用于切换用户身份,具体的用法如下:
```
su [-lmp] [-] [-s SH] [USER [SCRIPT ARGS / -c 'CMD' ARG0 ARGS]]
```
其中,各个参数的含义如下:
- -l:清除环境变量,回到目标用户的主目录,并作为登录 shell 运行。
- -p 或 -m:不设置新的 $HOME、$SHELL、$USER、$LOGNAME 变量。
- -c CMD:将 CMD 命令传递给 sh -c 执行。
- -s SH:使用指定的 SHELL 作为 shell,而不是使用目标用户的默认 shell。
- USER:要切换到的目标用户的用户名。
- SCRIPT ARGS:执行指定的脚本并传递参数。
- -:不指定任何参数时,切换到 root 用户。
例如,要切换到用户名为 john 的用户身份,并执行 /path/to/your/script.sh 脚本,可以使用以下命令:
```
su john -c "bash /path/to/your/script.sh"
```
需要注意的是,在使用 su 命令切换用户身份时,需要输入目标用户的密码才能切换成功。同时也需要注意谨慎操作,避免误操作造成不必要的损失。