First, the experimental environment:
installed a Red Hat Enterprise Linux 6.0 can run the system and is a successful verification system. There is another unprivileged user student, password student account exists.
Second, the experimental requirements:
1 , using alias Create aliases
2 , using PS1 Modify Bash the prompt
3 , write a simple Shell Small Program
Third, the experimental steps:
Create aliases C:
[[Email protected]~]$ alias c= ' Clear ' [[email protected]~]$ alias alias l.= ' ls-d. *--color=auto ' Alias Ll= ' Ls-l--co Lor=auto ' Alias ls= ' Ls--color=auto ' Alias vi= ' vim '
Run aliases C:
[Email protected]~]$ c
aliases are not saved at this time, and aliases are lost when you log off. To make this alias available to the user student every time you log in, you need to save it.
Modify . BASHRC file, save the alias created:
[Email protected]~]$ vim. BASHRC
The original file appears as follows:
#. bashrc# Source Global definitionsif [-F/ETC/BASHRC]; Then. /etc/bashrcfi# User specific aliases and functions |
Add a line at the end of the file:
Alias c= ' Clear '
after the save exits, log off the login again, alias C can still be used.
Use PS1 Command Change Bash Tips
[Email protected]~]$ ps1= ' Red hat-> ' red hat-> ls
Modify Bash revert to host name and traditional dollar sign
Red hat-> ps1= ' \h $ '
Modification succeeded:
localhost $
Recovery History Tips :
localhost $ ps1= ' [\[email protected]\h\w (\!)] $
Modification succeeded:
[[Email protected]~ (16)]$
Write a Shell script, when you enter Yes When you return No
#!/bin/bash#if you enter yes it'll echo no#if you enter no it'll echo Yes echo "you want yes or no:" Read ANSWER $vi te st_scriptif["$ANSWER" = "YES"]| | ["$ANSWER" = "yes"];then echo "Your idea is No"; elif["$ANSWER" = "No"]| | ["$ANSWER" = "no"];then echo "Your idea was YES"; else echo "You were wrong"; fi |
Use ./ Run the script Test_script
$./test_script-bash:./test_script:permission denied
But not enough permissions
[Email protected]~] $ll test_script-rw-rw-r--1student student 304 05:02 Test_script
ll View the file does not have Execute permissions
[Email protected]~] $chmod u+x test_script
Add execute permissions for this file
[Email protected]~] $lltest _script-rwxrw-r--1student student 304 05:02 Test_script
Run again
[Email protected]~ (]$./test_script) want YES or No:yesyour idea is NO
Using the alias and PS1 commands under Linux