The Bash prompt change
Introduction
The Bash prompt can do much more than displaying such simple information as your user name, the name of your machine and some indication about the present working directory. We can add other information such as the current date and time, number of connected users etc.
Before we begin, however, we will save our current prompt in another environment variable:
[jerry@nowhere jerry]$ MYPROMPT=$PS1
[jerry@nowhere jerry]$ echo $MYPROMPT
[\u@\h \W]\$
[jerry@nowhere jerry]$
When we change the prompt now, for example by issuing the command PS1 ="->" , we can always get our original prompt back with the command PS1 =$MYPROMPT . You will, of course, also get it back when you reconnect, as long as you just fiddle with the prompt on the command line and avoid putting it in a shell configuration file.
7.2.4.2. Some examples
In order to understand these prompts and the escape sequences used, we refer to the Bash Info or man pages.
*
export PS1 ="[\t \j] "
Displays time of day and number of running jobs
*
export PS1 ="[\d][\u@\h \w] : "
Displays date, user name, host name and current working directory. Note that \W displays only base names of the present working directory.
*
export PS1 ="{\!} "
Displays history number for each command.
*
export PS1 ="\[\033[1;35m\]\u@\h\[\033[0m\] "
Displays user@host in pink.
*
export PS1 ="\[\033[1;35m\]\u\[\033[0m\] \[\033[1;34m\]\w\[\033[0m\] "
Sets the user name in pink and the present working directory in blue.
*
export PS1 ="\[\033[1;44m\]$USER is in \w\[\033[0m\] "
Prompt for people who have difficulties seeing the difference between the prompt and what they type.
*
export PS1 ="\[\033[4;34m\]\u@\h \w \[\033[0m\]"
Underlined prompt.
*
export PS1 ="\[\033[7;34m\]\u@\h \w \[\033[0m\] "
White characters on a blue background.
*
export PS1 ="\[\033[3;35m\]\u@\h \w \[\033[0m\]\a"
Pink prompt in a lighter font that alerts you when your commands have finished.
*
export PS1 =...
Variables are exported so the subsequently executed commands will also know about the environment. The prompt configuration line that you want is best put in your shell configuration file, ~/.bashrc .
If you want, prompts can execute shell scripts and behave different under different conditions. You can even have the prompt play a tune every time you issue a command, although this gets boring pretty soon. More information can be found in the Bash-Prompt HOWTO .
Shell Variables
A shell variable is defined by the set command and deleted by the unset command. The main purpose of your .cshrc file is to define such variables for each process. To define a new variable or change the value of one that is already defined, enter:
% set name=value
where name is the variable name, and value is a character string that is the value of the variable. If value is a list of text strings, use parentheses around the list when defining the variable, e.g.,
% set name=(value1 value2 value3)
The set command issued without arguments will display all your shell variables. You cannot check the value of a particular variable by using set name, omitting =value in the command; this will effectively unset the variable.
To delete, or unset, a shell variable, enter:
% unset name
### new line in bash scripting ###
echo -e
###let##
"let" command in bash scripting is something like n++ or n-- in other lang of programming
and uses this way:
let "$VARIBLE += 1" or "$VARIBLE -= 1"
---- "for" stractare
for 'here_is_varibales_name_without_any_qouts' in 'something(for example `ls -ltr` or FIRST SECOND THIRD)';do
echo
let "$VIRABLE += 1"
done
###while###
-----------
impotant big letters in virables too while loop
TEST=0
TEST1=9
---- "while" stracter
while [ something(for example) $TEST -lt $TEST1 ] ; do
let "TEST += 1" # for loop to stop,otherwise it is not stop
echo $TEST
done
While read line # Read lines from the file
do
print $line
done<file_name.txt
###until###
-----"until" stracter
until [];do
let "$VARIBLE -= 1" # usully is down count script "-= 1" unlike "while" loop
echo
done
###"$#" ###
--- "$#" is possition paramater
the same is $1 or $3 is possition paramaters too
--- "select" options to build menu stracture
VAR1="CHIOSE1 CHOISE2 CHOISE3"
select i in "$VAR1" ; do
echo
done
###case###
----------- case options
#!/bin/sh
[ -f /etc/init.d/sshd ] || exit 199 # check if file exist
case "$1" in
start )
echo "Starting"
/etc/init.d/sshd start
;;
stop)
echo "Stoping"
/etc/init.d/sshd stop
;;
*)
echo 'Usage is start|stop'
exit 101
;;
esac