Raiders notes 4-- shell alias, the information collection terminal

Alias is a convenient way, you can save the trouble of a long list of input command sequence for the user. Below we will see how to
create an alias using the alias command.
Direct use of alias alias which is currently displayed, otherwise create an alias

[root@dns-node2 ~]# alias   # 显示别名
alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'

[root@dns-node2 ~]# alias mycmd='ls /root'  # 创建别名
[root@dns-node2 ~]# mycmd
anaconda-ks.cfg  Desktop  Documents  Downloads  install.log 

In the command line to create an alias is temporary. Once this closes the current terminal, setting off an alias on the failure, for permanent, we need to import to / etc / profile or ~ / .bashrc under

[root@dns-node2 ~]# echo "alias mycmd='ls /root'" >>/root/.bashrc

Want to break the alias, then it \ quotes
an example:

[root@dns-node2 ~]# \mycmd
-bash: mycmd: command not found
[root@dns-node2 ~]# \ls  # 非别名是无效的即使加上\
anaconda-ks.cfg  Desktop  Documents  Downloads  install.log  install.log.syslog  Music  ossec-hids-2.8.3  ossec-hids-2.8.3.tar.gz  Pictures  Public  Templates  Videos
[root@dns-node2 ~]# \ll
-bash: ll: command not found

Information collection terminal

When writing a command-line shell script, it was always going to deal with the current terminal-related information, such as number of rows, number of columns, cursor position,
covering the password field and so on.
tput and stty are two good tool

tput

1. Get the number of rows and columns of terminals:

tput cols
tput lines

2. Print out the current terminal name:

tput longname

3. Move the cursor to the coordinates (100, 100):

tput cup 100 100

4. Set the terminal background color:

tput setb n

Where, n may be between the values 0 to 7.
5. Set the terminal foreground:

tput setf n

Where, n may be between the values ​​0 to 7.

6. Set the text style to bold:

tput bold

7. Set the start and end underline:

tput smul
tput rmul

8. Remove all the current cursor position to the end of the line:

tput ed

9. Enter the password, the script should not display the input content. In the following example, we will see how to use stty to
achieve this requirement:

stty -echo  # 此时隐藏所有的输入
stty echo   # 显示所有的

9.1 Specific examples of reference:

#!/bin/sh
#Filename: password.sh
echo -e "Enter password: "
#  在读取密码前禁止回显
stty -echo
read password
#  重新允许回显
stty echo
echo
echo Password read
Interesting countdown
#!/bin/bash
#文件名: sleep.sh
echo Count:
tput sc   # 存储光标的位置
# 循环40秒
for count in `seq 0 40`
do
    tput rc   # 恢复之前存储的光标的位置
    tput ed    # 清除从当前光标位置到行尾之间的所有内容,行被清空之后,脚本就可以显示出新的值。
    echo -n $count
    sleep 1
done

Guess you like

Origin www.cnblogs.com/liaojiafa/p/11470411.html