Wedge
Recently like the script so learn a little bit and solidify yourself.
Simple Log emptying note! This is a test environment that can be emptied freely.
Cd/var/log
Cat/dev/null>messages
echo "Logs cleaned up."
One, can vim a file name example test.sh
The empty log script is as follows:
#!bin/bash
#清除日志脚本, Version 2
Log_dir=/var/log
Root_uid=0 #<== $UID to 0 users, that is, the root user
#脚本需要root用户权限来运行, therefore, to judge the current user, for non-compliant users to give a friendly
Prompt, and the finalizer runs.
If ["$UID"-ne "$ROOT _uid"]#<== does not execute the script if it is not the ROOT user.
Then
echo "must is root to run this script." #<== gives an exit hint.
Exit 1 #<== the script.
Fi
#如果切换用户到指定目录不成功, the prompt is given and the terminal program runs.
CD $LOG _dir | | {
echo "Cannot change to necessary directory."
Exit 1
}
#经过上述两个判断后, the user rights and paths here should be right, only clear the success, to prompt printing
Prompt for success.
Cat/dev/null>messages && {
echo "Logs cleand up."
Exit 0 #<== returns 0 before exiting, indicating success, and returning 1 means failure!
}
echo "Logs up fail."
Exit 1
Second, the Enterprise face questions
What is the default shell for the CentOS Linux system? What are the commands for viewing?
Answer: 1.bash 2.echo $shell or grep root/etc/passwd
Third, in the Liunx system, shell scripts (bash shell programs) are usually written in the editor Vi/vim, consisting of unix/linux commands, bash shell commands, Program structure control statements, and annotation content. It is recommended to use the powerful Vim editor of Linux to write, you can make a nickname alias Vi= ' Vim ', and make it permanent, so that after the custom Input VI partners can also call the Vim editor directly, the method is as follows!
# echo "Alias" vi= ' Vim ' ">>/etc/profile
# TAIL-1/etc/profile
After execution, it will appear as follows: Alias Vi= ' vim '
#soure/etc/profile
Summarize! The above is the introductory script, refueling!
This article from "Li Shilong" blog, declined reprint!
Enterprise Interview Shell Entry script questions