By Rekha H, Pooja Jaiswal
Here comes the first CIA component which brings the opportunity to try our hands on something new in UNIX.
We got the topic as “bourne shell,.profile and history “.Getting this topic we promptly wanted to change it ,but truely speaking ,later we realized it is very interesting..
Consider when you open the unix terminal and see the prompt as “eat more put on weightJ” or “party all night sleep all day” instead of that same boring stupid ” $” symbol…will it not be better or what if you can write your own thoughts..?
We totally agree that history is a boring sleepy subject,since we had to remember dates,wars..etc which we could hardly relate. But we assure you history in unix will not trouble you in any way like this …nothing to remember ..and yes ,forgetting is allowedJ.
Another thing to discuss about is .profile which will make u feel- “my UNIX my way “.
Now we explore several commands with examples to make it more clear..
The prompt Strings (PS1 and PS2)· The shell has two prompts.
*The primary prompt string PS1 is the one you normally see-$.
*The > is the secondary prompt string stored in PS2.
You can do interesting things in this by changing the prompt your way -
Eg.1:
$PS1=”C>”
C>
Eg.2: Feels good to see such a nice prompt!!!!
$PS1='pooja and rekha are good friends:'
*The prompt has changed now--
pooja and rekha are good friends: man ls
*To know your present working directory :-
pooja and rekha are good friends: pwd
/home/rekha
To know the user name :-
pooja and rekha are good friends: who am i
rekha pts/0 2011-06-27 09:20 (:0)
Eg.3: start thinking smart…with smarter prompts!
$ PS1='Think smart:'
Command History
· The History command displays the history list showing the event number of every previously executed command
· A command is recalled by using this event number with a symbol like ! or r.
· While Bash displays the complete history list with history, korn list the 16 commands most recently used.
· If you wish to find last 5 executed commands then the simplest way is –
history 5 bash àthis is how you see the last five
commands executed
history -5 korn à this is for korn shell,to get last five
commands executed.
The output shows the event number and command associated with that number and it could look like this:
35 set -o ignoreeof
36 exit
37 alias l=`ls –l`
38 tar cvf /dev/fd0 *.doc
40 history
· When a command is entered and executed, it is appended to the list.
So wasn’t this easy J!!!!!!!!!!!
Accessing previous Commands by Event numbers (! and r)
· You can simply type ! or r to access the previous commands
· ! - bourne
· r - korn shell
· If you want to repeat the last command, you have to use this:
!! Repeats previous command à Bash
r Repeats previous command à Korn
Eg:
$ !38
38 tar cvf /dev/fd0 *.c àthis was the executed command # 38
See.. how easy it is to access any previous command reducing the effort to type again…try it out !!!!
Executing previous commands by contextA common problem of bad memory is always associated with human beings …isn’t it? But there remains something in mind like if not the event numbers... At least you remember that the command started with a specific character.
So no worries! Unix brings you the facility of repeating the command just by typing beginning letter/string of the command
· Like if you know that the last command name beginning with v was the vi command, you can use ! or r with either v or vi to repeat the last vi command:
!v à Repeats last command starts with v à bash
r v à Repeats last command starts with v à korn
NOTE:
· you can also use !c for compiling a C program and
· !v for editing(r c and r v in korn);
This is even simpler!!!!!!!!
Substitution in Previous commands
· Often you need to execute a previous command but only after replacing a string in the command line with another.
· The same history symbol (! in bash and r in korn) allow you to do that by following the normal repeat command with a substitution instruction.
Bash uses the vi- style :s command and the / as delimiter of the old and new patterns.
So if you want to repeat the previous tar command, but this time using the .bak
So instead of the .doc files, you have to replace with bak in this way:
! tar :s/doc/bak à Bash – vi also uses :s for substitution
r tar doc=bak àKorn
?????history reminded ???????
The profile (.profile)
· The bourne family uses .profile as the login script
· This .profile file will be available in the list of files.
Eg. $ cat .profile
# User $Home/.profile –commands executed at login time
MAIL=/var/mail/$LOGNAME à tells you the mailbox location
PATH=$PATH:$HOME/bin/usr/ucb:
PS1=’$’
PS2=>
TERM=vt100
MOZZILLA_HOME=/ opt/netscape ;
stty stop ^S intr ^C erase ^?
Echo “ today’s date is `date`”
No comments:
Post a Comment