我正在制作一个迷你欢迎脚本.zshrc
。该脚本是(我想$TTYNUMBERGOESHERE
用 tty 号码替换,但用一个变量使其在每个终端上自动更新);
clear
echo "Welcome to Mehmet Akif's Linux!"
echo
echo " * $USER on MadLinux."
echo " * Using $TTYNUMBERGOESHERE."
echo
echo "Type 'startx' to start graphical user interface."
echo
答案1
只需使用tty
命令:
clear
echo "Welcome to Mehmet Akif's Linux!"
echo
echo " * $LOGNAME on MadLinux."
echo " * Using $(basename $(tty))"
echo
echo "Type 'startx' to start graphical user interface."
echo
或者,更整洁一点:
clear
printf '%s\n\n%s on MadLinux.\nUsing %s\n\n%s\n\n' \
"Welcome to Mehmet Akif's Linux!" \
"$LOGNAME" \
"$(basename $(tty))" \
"Type 'startx' to start graphical user interface."
或者,使用此处文档:
clear
cat <<EoF
Welcome to Mehmet Akif's Linux!
$LOGNAME on MadLinux.
Using $(basename $(tty))
"Type 'startx' to start graphical user interface."
EoF
实际上,zsh
还有一种更简单的获取 tty 名称的方法:$TTY
变量。所以你可以使用:
clear
cat <<EoF
Welcome to Mehmet Akif's Linux!
$USER on MadLinux.
Using "${TTY#/dev/}"
"Type 'startx' to start graphical user interface."
EoF