JAVA SCRIPT

RH033 5. SHELLS IN LINUX (BASH):

The Linux/Unix shell refers to a special program that allows you to interact with it by entering certain commands from the keyboard;
the shell will execute the commands and display its output on the monitor. Default shell of linux  is /bin/bash..

TYPES OF SHELLS SUPPORTED :

/etc/shells    =Shows shells supported by linux
/bin/sh        =Bourne shell
/bin/bash      =Bourne again shell
/sbin/nologin  =Nologin shell,usually given for system users
/bin/tcsh      =Turbo c shell
/bin/csh       =c shell
/bin/ksh       =korn shell


#<shell>  Type and shell, and enter takes you to that 
                  particular shell

#ctrl d         --> Logs out from shell

echo $0     -> Shows current shell name

echo $SHLVL      -> Current shell level


FEATURES OF BASH SHELL:

  1. command line completion
  2. command line expansion
  3. command line history
  4. command line shortcuts
  5. File globbing and wild card character


1.  Command line completion
     Completes filename and command using tab.  Type 1/2 letters of command and press tab, it will auto complete....

2. command line expansion

    a> Arithmetic expansion     //echo <text> =Prints text
       a=43                    //echo $a     =Prints value of a variable
       b=534
       echo  $[$a + $b]


    b> Quote expansion               //Executes command
       echo `date`                             //backquotes below escape key
       echo `ls -l`  

         
    c> Brace expansion       
       mkdir redhat{1,2,3,4,5}
       rmdir redhat{1,2,3,4,5}
      
3. Command line history

    history  =Shows history of commands
    !<char>  =Executes command starting with character
    !<num>   =Executes command starting with number

4. Command line shortcuts

    ctrl a =Beginning of line
    ctrl e =End of line
    ctrl c =Gets back command prompt
    ctrl d =Log out
    ctrl l =Clear screen
    ctrl z =Stop process   //yes <text> =Print text infinite times
    ctrl u =cut/copy line
    ctrl y =Paste whatis cut/copied
    ctrl w =Delete text after cursor
    ctrl k =Delete text before cursor


5. File globbing and wild card character

    ls  a*  =List files starting with a  //you can list/copy/remove
    ls  *a  =List files ending  with a  
    ls  *a* =Files just having letter a
    ls  ?   =List single lettered file
    ls  ??  =Double lettered file


    SHELL SCRIPT --> Used to automate jobs.

   1. To Create file

 # vim file1.sh           //Opens/create file                                                                    
 i    //Allows you to insert contents,
  
   echo "Calender for month is `cal` "                         
   echo "Number of users logged in `who` "
   echo "List of files in my home dir `ls /root` "
  
 :wq          //Save and quit file


  2. TO Execute file  (3 methods to execute file)

     sh <file>

     ./  <file>   //For using this method give chmod 744 to file

     source <file>





No comments:

Post a Comment