Unix Commands Part 5

Shell and programming


Shell programming,bourne shell, ksh, csh, echo,line,sleep, test,cc compiler.

Shell programming concepts and commands.

Shell programming is integral part of Unix operating systems. Shell is command line userinterface to Unix operating system, User have an option of picking an interface on Unix such as ksh, csh, or default sh., these are called shells(interface). Shell programming is used to automate many tasks. Shell programming is not a programming language in the truest sense of word since it is not compiled but rather an interpreted language. Unix was written in C language and thus c language is integral part of unix and available on all versions. Shells, like ksh and csh are popular shells on unix although there are 5 or 6 different shells available but I will only be discussing ksh and csh as well as sh. Common features among all shells are job control, for example if I am running a processes which is searching the whole system for .Z files and output is directed to a file named compressedfiles.

    example:
  • find / -name *.Z -print > compressedfiles

    then after entering this command hitting


  • key will suspend this job, then entering
  • bg

    at command line will put this job in background, entering
  • fg

    will put this job in foreground. Entering
  • jobs

    at command line will show me all my concurrent jobs that are running.
      Other common features
    • > will redirect output from standard out (screen) to file or printer or whatever you like.
    • >> filename will append at the end of a file called filename.
    • < will redirect input to a process or commnand.
    • | pipe output, or redirect output, good for joining commands, i.e. find command with cpio, etc.
    • & at the end of command will run command in background.
    • ; will separate commands on same line.
    • * will match any characters in a file or directories. junk* will match all files with first 4 letters
    • ? will match single characters in a file.
    • [] will match any characters enclosed.
    • () execute in subshell.
    • ` ` to run a command inside another command and use its output.
    • " " partial quote for variables.
    • ' ' full quote for variables.
    • # begin comment (if #/bin/ksh or csh or sh is entered at first line of script it runs script in that shell)
    • bg background execution.
    • break break from loop statements.
    • continue Resume a program loop.
    • Kill pid number will terminate running jobs
    • stop will stop background job.
    • suspend will suspend foreground job.
    • wait will wait for a background job to finish.

Bourne Shell (sh shell).

sh or Bourne shell is default shell of Unix operating systems and is the most simplest shell in Unix systems.

    Examples:
  • cd; ls execute one after another.
  • (date;who;pwd)> logifile will redirect all the output from three commands to a filenamed logfile.
  • sort file | lp will first sort a file and then print it.
  • alias [options] [name[='command']] will let you create your own commands. i.e.
    • alias ll="ls -la" will execute `ls -la` command whenever ll is entered.
  • let expressions is syntax of let statement.
    • let i=i+1 will work as a counter with i incrementing each time this statement is encountered.
  • for x[in list] do commands done is syntax for for do loop.
  • function name {commands;} is the syntax of a function which can be called from anywhere in program.
  • if condition1 then commands1 elif condition2 then commands2 ... ... ... else commands3 fi

Ksh shell (Korn).

Ksh or Korn shell is widely used shell.


Csh or C shell

csh is second most used shell.


Echo command

echo command in shell programming.


Line command.

line command in shell programming.


Sleep command.

sleep command in shell programming.


Test Command.

test command in shell programming.


CC compiler (c programming language compiler).

Since Unix is itself written in C programming language, most Unix operating systems come with c compiler called cc.




Comments

Popular posts from this blog

Linux File and Directory Permissions

How to Disable SSL for Webmin

INSTALL CISCO VPN CLIENT ON WINDOWS 10 (32 & 64 BIT). FIX REASON 442