C Shell (csh) or tcsh:

C shell was created by Bill Joy of UCB in 1978, shortly after release of sh shell. It was developed to make coding style similar to C language (since C was the most used language for programming at that time), and make it easier to use. Later a improved version of csh called tcsh was developed which borrowed a lot of useful concepts from Tenex systems, hence the "t". On most linux systems, tcsh is the shell used (even though it says csh, it's actually tcsh, as csh is usually a soft link to tcsh binary).

NOTE: Even though we say csh everywhere, it's really tcsh that we are talking about. Extensions still say *.csh. We'll call it csh even though we mean tcsh.

This is  offcial website for tcsh: https://www.tcsh.org/

This is good website for all shell/linux related stuff: (The guy lists a lot of reasons on why csh shouldn't be used): https://www.grymoire.com/Unix/Csh.html

Bill Joy's csh intro paper here: http://www.kitebird.com/csh-tcsh-book/csh-intro.pdf

csh syntax: https://www.mkssoftware.com/docs/man1/csh.1.asp

NOTE: C shell is not recommended shell for usage. Bash is the one that should be used. Almost all of linux scripts, that you find in your linux distro, are in bash. Csh is introduced here, since some scripts in corporate IT world are still written in csh, which you may need to work on from time to time. Csh is ripe with bugs, and you can find a lot of articles as to why Csh should not be used. One reason why csh is so buggy and unpredictable is because it doesn't have a true parser like other shells. Bill Joy famously admitted that he wasn't a very good programmer when he wrote csh. To make matters worse, there is no elaborate documentation of csh (unlike bash, which has very detailed documentation on tldp.org website). The only doc that shows up most frequently on internet searches is that "bill Joy's csh" paper, whiich is like decades old (shown in link above). This makes it hard to systematically learn csh. What I've documented below is just bits and pieces from diff websites, as well as my own trial and error with csh cmds. In spite of all this, csh became so popular, which just bewilders me. Hope, I've convinced you enough not to read thru the csh doc below.

Csh startup files: uses 3 startup files:

1. .cshrc: It's sourced everytime a new C shell starts. The shell does a "source .cshrc". csh scripts also source this file, unless "-f" (i.e fast) option is used on cmd line or on 1st line of csh script

ex: #!/bin/csh -f => -f option as 1st line of script causes csh to startup in fast mode, i.e it reads nether the .cshrc nor the .login

2. .login: If you are in a login shell, then this file is the 2nd file sourced. after the .cshrc file.

3. .logout: This is the last executed on logging out (only from a login shell)

Simple csh script example: similar to bash, except for 1st line. Save it as test.csh.

#!/bin/csh -f

echo "hello"; => this cmd followed by args. Each line of csh is "cmd followed by args"

Run this script by doing "chmod 755 test.csh", and then typing ./test.csh.

csh itself has many options that can be provided on cmdline that controls it's behaviour.

ex: csh -f -v -x ... => many more options possible. -x is an important option that echoes cmds immediately before execution (this is useful for debug)

Csh Syntax:

csh is very similar to C in syntax. Similar to bash, we'll look at reserved keywords/cmds, variables and special char. On a single line, different tokens are separated by whitespace (tab, space or blank line). The following char don't need space to be identified as a separate token: &, &&, |, ||, <, <<, >, >>, ;, (, ). That's why many special char such as + need space around them since w/o a space, csh is not able to parse it into a token.

As in bash, each line in csh is a cmd followed by args for that cmd. Separate lines are separated by newline (enter key), semicolon (;) or control characters (similar to bash).

A. Commands: similar to bash, csh may have simple or complex cmds.

1. simple cmd: just as in bash, they can be built in or external cmd. Few ex:

  • alias: same as in bash, but syntax little different. Alias are usually put in initialization files like ~/.cshrc etc so that the shell sees all the aliases (instead of typing them each time or sourcing the alias file). One caveat to note is that Aliases are not inherited by child processes, so any csh script that you run will not inherit these alias until you redefine these alias again in your script.
    • ex: alias e 'emacs'. => NOTE no "=" sign here (diff than bash where we had = sign). Now we can type "e" on cmd line and it will get replaced by emacs and so emacs will open.

2. complex/compound cmd: They are cmds as if-else, while, etc. They are explained later.

B. Variable: csh needs "set" cmd to set variables, unlike bash which just uses "=". Everything else is same. $ is used to get value of a variable assigned previously. There are 2 kinds of var: global and local var

1. local var: local vars are assigned using set and "=" sign, i.e set var = value. NOTE: we can use spaces around = sign, unlike bash where no spaces were allowed. This is because "set" keyword is the assignment cmd, and rest is arg, so spaces don't matter. In bash, the whole assignment thing was a cmd.

set libsdir = "/sim/proj/"$USER"/digtop_$1" => spaces around = sign. $ inside double quotes or outside, is always expanded.
echo "myincalibs = " $libsdir => prints: myincalibs = /sim/proj/ashish/digtop_abcd

2. global var: For global var, we need to use "setenv" and no = sign. i.e: setenv HOME /home/ashish. No separate "export" cmd needed (as in bash). setenv cmd by itself does export too, so that the var is accessible to subshells. To see list of global var, we can use cmd "setenv" by itself with no args (we can also use env and printenv cmds from bash). Most of the global vars such as HOME, PATH, etc are same as those in bash.

setenv RTL_FILES "${DIGWORK}_user/design/svfiles.f" => {} allows the var inside braces only to be used for $ subs. NOTE: no = sign. setenv (rather than set) is used for global var (we used setenv so that this variable can be used in other scripts running from same shell).

$? => this checks for existence of a var. i.e $?HOME will return 1 (implying var exists), while $?temp123 will return 0 (implying var doesn't exist). This has different meaning in bash, where it expands to exit staus of most recently executed foreground pipeline. So, $?HOME will return 0HOME if the cmd run just before this was a success, or return 127HOME if cmd run just before this was in error, where 127 is the error code

prompt: Terminals with csh usually show a "%" sign as prompt. setting prompt in csh is same as setting other global vars. To set prompt in csh, we use keyword prompt instead of PS1. However, prompt keyword itself doesn't work in many c shells.

echo $prompt => on my centos laptop when in csh, it shows "%%[%n@%m %c]%#"
set prompt = " $cwd %h$ " => doesn't work at some corporations, as csh is actually tcsh (even though echo says its /bin/csh, installed pkg are always tcsh as tcsh is improved version of csh, and csh is just a soft link to tcsh), so use tcsh cmds. tcsh is backward compatible with csh, but somehow this cmd doesn't work. So, correct way would be:
set prompt = "[%/] > " => this worked on  m/c, but not guaranteed to work on others.

Data types: variables can be of diff data types. Looks like as in bash, primitive data types here are char string.

1. String: Everything is char string. It's internally interpreted as integer numbers depending on context.

ex: set a=12; set b=13; @ c= $a + $b; echo $c will print 12 +13=25 since it will treat those 2 var as integer. @ is special cmd used to assign a calculated value. For + to be treated as an arithmetic operator, there has to be space on both sides of +, else it will error out. NOTE: it doesn't use "set" cmd to assign a arithmetic calculated value.

ex: set a=12; set b=13; set c=$a+$b; echo $c will print "12+13", since it will treat the whole thing on RHS as a string (those 2 var and + are all string). NOTE: it uses "set" cmd here for string assignment.

ex: set d=jim => this assigns a string "jim" to var "d" even though it's not enclosed in double quotes. We would have needed to use single or double quotes if we had special char inside the RHS string as space, $, etc.

2. array: array contains multiple values. syntax same as in bash. However, here index start from 1 instead of 0 (in bash, index start from 0). Also, assciative array don't seem to work in csh.

ex: my_array=(one two three) => this assigns my_array[1]=one, my_array[2]=two and so on.

ex: echo $my_array[2] => this prints "two" even though curly braces are not used. Not sure why this works. NOTE: in bash, echo ${my_array[2]} was needed to print correctly. So, to be on safe side, always use curly braces around var to remove ambiguity.  "echo $my_array[0]" would print nothing as there is no index 0.

ex: echo $my_array => this would print all array, i.e "one two three", unlike bash, where it prints just the 1st element of array, i.e "one"

ex: set my_array[2]=one => If we do "echo $my_array[2]" it will print "one" as the array got overwritten at index=2.

ex: set me[1]="pat" => this doesn't work, as arrays can only be assigned via ( ... ). We can later change the value of any index of array using this syntax, but we can't define a new array using this. If we do "echo ${me[1]}" then it gives an error "me: Undefined variable" as csh looks for array "me" defined using parenthesis ( ... ) and tries to get value for index=0. In this case, "me" was never defined to be an array

ex: my_array[name]='ajay'; => associative array don't work in csh

C. Special Characters or metacharacters: This is mostly same as in bash. cmd line editing in bash was basically taken from csh, so all cmd line edit keys from bash work in csh.

special character usage:  special char are mostly same as in bash.

1. # => comment. This is single line comment. If you want to comment multiple lines, use "if" cmd explained later. As explained in "bash" scripting section, comment line is not completely ignored in csh, in contrast to bash. The "\" character at the end of comment line is looked at to figure out if the newline at the end of comment should be escaped or not. Comment is still ignored. So, very important to carefully look at any comment line, and put a backslash at end of it, if a regular cmd there would have needed a backslash. Look at backslash description in bullet 2 below. Let's look at an ex below:

ex: foreach dirname ( dir1 \

dir2 \

#dir3 \

)

In above ex, dir3 is commented out and has a "\" at end. So, the whole line until "\" is ignored. "\" at end escapes newline, so contents of next line are treated as part of same line. This is how it looks after expanding:

foreach dirname ( dir1 dir2 ) => Here "dir3" is completely ignored as it's in comment except for "\" which causes continuation of line 4 (closing barces) on line 3 itself. NOTE: \ at end is NOT continuation of comment, i.e it's not like this: foreach dirname ( dir1 dir2 #dir3 ) => this would have caused an error as closing brackets won't be seen by csh interpreter. This is not what happens in csh.

ex: The below ex causes a syntax error "Too many ('s". This is because closing bracket ) is seen on another line, so it's like this foreach dirname ( dir1 dir2 => so ) is not on same line resulting in error.

foreach dirname ( dir1 \

dir2 \

#dir3

)

 

2. " ' \ => same as in bash, they hide special char from shell.

I. Double Quotes " " : weak quoting

II. Single Quotes ' ': strong quoting

III. Backslash \ : hides all special characters from the shell, but it can hide only one character at a time. So, it can be used to hide newline character at end of line by putting backslash at end of line (this allows next line to be seen as part of current line). There is slight variation to this for the comment line as shown in example above (backslash at end of comment line is not seen as continuation of comment line).

3. End of cmd: Same as in bash, a newline character (by pressing enter/return) is used to denote end of 1 cmd line. For multiple cmds on same line, semicolon (;) can be used to separate multiple cmd. There has to be a space after semicolon, else parser will not see ; as a token.

Control operators: Same as in bash. Pipe cmd and list work same way.

4. source or . cmd: same as in bash

5. backquote or backtick (`): same as in bash. However, the o/p here is stored in an array, instead of a simple string

ex: a=`ls`; echo $a; => This will print the array a (as o/p of this is stored in array). To see individual elements of array, we can do $a[1], $a[2]. etc (NOTE: $a[0] is not valid as arrays start with index=1 in csh)

6A. user interaction: All languages provide some way of getting i/p from a user and dumping o/p. In bash, we can use these builtin cmds to do this:

Output cmds: echo cmd supported.

Input cmds: csh has "$<" for reading i/p.

ex: below cmd reads i/p from terminal and prints the o/p

echo -n Input your number:

set input = $<

echo You entered $input

6B.  IO redirection: same as in bash.

7. Brackets [ ] , braces { } and parenthesis ( ) : same as in bash. [] and {} are used in pattern matching using glob. All [], {}, () are used in pattern matching in BRE/ERE. See in regular expression section. However, they are used in other ways also:

I. single ( ) { } [ ]:

( ) { } => these are used to group cmds, to be executed as a single unit. parenthesis (list) causes all cmds in list to be executed in separate subshell, while curly braces { list; } causes them to be executed in same shell.

{ } => Braces { } are also used to unambiguously identify variables. They protect the var within {} as one var. { ..} is optional for simple parameter expansion (i.e $name is actually simplified form of ${name})

{ } can also be used for separate out a block of code. spaces should be used here. ex: a=3; { c=95; .... } echo $c;

[ ] => square brackets are used for globbing as explained above.

[ ] are also used to denote array elements as explained in array section above.

arithmetic operators: One of the most useful feature of csh, which is missing in bash, is that csh allows direct arithmetic operations. No "expr" cmd needed to do numeric arithmetic. These arithmetic operations can appear in @, if, while and exit cmds. Many of these operators below return boolean "true" or "false", but there is no inbuilt boolean type. i.e if (true) ... is invalid. An expr has to be used that evaluates to true or false.

  • number arithmetic: +, -, *, /, %, **(exponent), id++/id-- (post inc/dec), ++id/--id (pre inc/dec)
  • bitwise: &, |, ^(bitwise xor), ~(bitwise negation), <<(left shift), >>(right shift). ~ is also used as expansion to home dir name.
  • logical: &&, ||, !(logical negation)
  • string comparison: ==(equality), !=(inequality),  These are not arithmetic comparisons but lexicographical (alphabetic) comparisons on strings, based on ASCII numbering. Here RHS has to be a string and not a pattern.
  • <=, >=, < ,>. => these operate on numbers (unlike bash, where these operate on string, and -lt, -ge, etc were used instead to compare numbers)
  • assignment: =(assigns RHS to LHS), *=, /= %= += -= <<= >>= &= ^= |= => these are assigments where RHS is operated on by the operator before =, and then assigned to LHS (i.e a*=b; is same as a=a*b.
  • matching: =~ this is a matching operator (similar to perl syntax) where string on RHS is considered ERE, and is matched with string on LHS. ex: [ $line =~ *?(a)b ] => returns true if string contains the pattern
    • seems like .* for ERE is not honored, but rather just plain * as used in glob. ex: $name =~ raj_.* doesn't match raj_kumar, but $name =~ raj_* (w/o the dot) does match raj_kumar
  • non matching: !~ this is non matching operator, where string on RHS is considered ERE. returns true  if strings doesn't contain the pattern.
  • condional  evaluation: expr ? expr1 : expr2 => similar to C if else stmt
  • comma : comma is used as separator b/w expr

ex: @ c=$a + $b; => @ needed to do arithmetc. No "set" cmd needed.

ex: @ num = 2 => this assigns numeric value 2 to num. If we used "set num = 2" then it assigns num to string 2. It may then still be interpreted as num or string depending on how it's used later.

ex: @ i++ => increments var i by 1

ex: if ($a < $b) echo "a < b"

II. double (( )) {{ }} [[ ]] => no known usage in csh

8. pattern matching: same as in bash

9. looping constructs: These 2 cmds used to form loops: foreach and while. "break" and "continue" builins are used to control loop execution, and have same behaviour as in bash. break exits the loop, not the script. continue continues the loop w/o going thru the remaining stmt in loop that are after continue.

  • foreach: It's a loop where the variable name is successively set to each member of wordlist and the sequence of commands until the matching end statement are executed. Both foreach and end must appear alone on separate lines.  syntax:
    • foreach name (wordlist)
               commands
           end
    • ex:
      foreach color (red orange yellow green blue)
              echo $color
           end
  • while: Just like foreach, it's a loop Statements within the while/end loop are conditionally executed based upon the evaluation of the expression. Both while and end must appear alone on separate lines.syntax:
    • while (expression)
               commands
           end
    • ex: set word = "anything"
           while ($word != "")
             echo -n "Enter a word to check (Return to exit): "
             set word = $<
             if ($word != "") grep $word /usr/share/dict/words
           end
  • break / continue: these are used in foreach or while loop statements above. "break" terminates execution of loop, and transfers control to stmt after the end stmt, while "continue" transfers control to the end stmt. So, "break" forces the pgm to exit the loop, while "continue" keeps on continuing with next iteration of loop (while skipping stmt in the loop that come after continue).
    • foreach number (one two three exit four)
             if ($number == exit) then
               echo reached an exit
               break (or use continue. break takes ctl to stmt right after "end" stmt, while continue takes it back to beginning of loop, to start with next iteration)
             endif
             echo $number
           end

10. Conditional constructs: same as in bash, syntax slightly different. Also these are closer to C lang in syntax, and have switch.

  • if-else: There are 2 variants of if cmd: A. if without else B. if with else
    •  if => if (expr) command [arguments] => here cmd must be a simple cmd, not piped cmds. There is no else clause.
      • ex: if ($#argv == 0) echo There are no arguments => all in one line
      • ex: if (-d $dirname) echo "dir exists" => this checks for existence of dir. options supported for existence of files/dir are same as those in bash
    •  if-then-else => if (expr) then (cmd1) else (cmd2) endif . There may be multiple else clauses here. "then" and "endif" are required in this form of if-else.
      • ex: if ($number < 0) then  
                   @ class = 0  
                else if (0 <= $number && $number < 100) then  
                   @ class = 1      
                else  
                   @ class = 3  
                endif
      • if ($dat == $vrfir) then => Note no semicolon used. == used (as in C)
          echo foo
        else => optional
          echo bar!
        endif
      • if-then may be used for multi line comments. ex: set debug=1; if ($debug == 1) then ........ endif
      • if (!(-e ${AMS_DIR}/net.v)) then ... else ... endif => checks for existence of a file. same options as in bash.
  • switch case: The switch structure permits you to set up a series of tests and conditionally executed commands based upon the value of a string. If none of the labels match before a `default' label is found, then the execution begins after the default label.  Each case has "breaksw" cmd at end of case that causes execution to continue after the endsw. Otherwise control may fall through case labels and default label may execute if there is no "breaksw". Also, the patterns for each case may contain ? and * to match groups of characters or specific characters. syntax is as follows:
    • switch (string)
        case pattern1:
          commands...
          breaksw
        case pattern2:
          commands...
          breaksw
        default:
          commands...
          breaksw
      endsw
    • ex: if ($#argv == 0 ) then
              echo "No arguments supplied...exiting"
              exit 1
           else 
              switch ($argv[1])
              case [yY][eE][sS]:
                echo Argument one is yes.
                breaksw
              case [nN][oO]:
                echo Argument one is no.
                breaksw
              default:
                echo Argument one is neither yes nor no.
                breaksw
              endsw
           endif
  • goto: The goto statement transfers control to the statement beginning with label:
    •      if ($#argv != 1) goto error1
           goto OK
           error1:
             echo "Invalid - wrong number or no arguments"
             echo "Quitting"
             exit 1
           OK:
             echo "Argument = $argv[1]"
             exit 1
    • if (.$RUN == ams) goto ams_run
      ....
      ams_run: => control transferred here
      ....
      exit

    •  goto is usually used to print usage info of a script when number of args is insufficient
      if ($#argv < 3) then
      goto usage
      else ... endif => process cmd line args
      usage:
      echo " shows usage of cmd" => This prints usage info for that script when cmd is typed
      exit

 
Advanced csh cmds: Read on csh links on top for more on this.

 

 

 

 

 

 

 

 

programming vs scripting languages

There are many different general purpose programming and scripting languages. Over the past decade, languages have exploded (both traditional languages and scripting languages, both referred to as programming languages now), and it's hard to even know where to start. There are 2 categories of languages: one is the traditional general purpose programming language as C, while other is scripting language as python.

1. general purpose programming languages: compiles in a binary code, and then binary is executed, so it's fast. Languages like C are an example of GP programming languages. C has been the most popular programming language since it's start in 1970. Almost every software big or small was coded in C, and it was the ONE language that everybody learned. Even today it's the most popular language used to build OS, desktop software, large enterprise systems, etc.

2. scripting languages: they are usually not compiled, but are interpreted at runtime by an interpreter. i.e they are read line by line, and then at end of each line, that line is translated to binary code to run on the computer. So they are slow to run. But now with such fast machines, for most of the user programs, scripts run almost as fast as compiled code. Scripting languages used to be very limited in scope (i.e they weren't meant for general programming, but as quick replacement to write simple scripts to do something), but things have changed now. Scripting languages have the same functionality as complex compiled languages, and are much easier to learn. Many of them are GP programming languages.

The lines have now blurred, and all languages whether compiled or interpreted are referred to as GP programming languages.

Which Language to learn?

There are so many programming and scripting languages out there, that it's intimidating. Which language should you learn and how much? Should you go for depth, i.e learn just one language, but learn it deep? Or should you go for breadth, i.e learn multiple languages, but not in too much depth? My philosophy is that you should never spend too much time going in depth, because that takes from you the ability to learn multiple things.

C, Java and Python are the 3 most popular languages as of 2020.

https://fossbytes.com/most-popular-programming-languages/

C has always been the most popular language, but since it's harder to learn for beginners, it's likely to lose it's top spot. Java is heavily used in software companies, and a huge driver for that is Android platform from google that supports Java. However, python is rapidly gaining popularity, because it's much easier to learn. In fact, more universities now teach Python in their introductory courses. Java is reserved for Advanced courses. If you have resource to learn one and only one language, I would strongly suggest learning Python.

There are many other languages that you will need to learn, since Python alone can't do everything. For ex, if you looking to build a website, you will need to know a little bit of HTML and CSS, and then use it with Python.  Another ex is that of a database language as MySQL. You will need to know little bit of MySQL so that you can integrate it with Python. We'll go thru all of these in next sections.

This is an essential list of programming languages that will suffice most of your needs:

Website Laguages: Learn HTML, CSS. Then learn Javascript for client side scripting and Php for server side scripting

Database Language: SQL is the Database language. MySQL is a software using SQL, but MySQL is usually referred to as the Language itself (they are tightly integrated with each other) It's mostly used in Web applications, and knowing at least 1 Database Language is a must.

Desktop Applications: C, Java and Python will suffice here. These are traditional GP programming languages that you write programs in, on your laptop to build a game, app, etc.

NOTE: If you are trying to learn a language to get a job, I've no clue of which language to learn. However if you re looking to learn a langauge to solve your own problem, to code your own program or just to have fun, then any language will do just fine, provided it's easy to learn. Python just fits all of that.

Resources: Below I'm going to list few excellent websites for learning coding. they are all free, and a lot of material that I've on my website, is based of these:

1. Tutorials Point => https://www.tutorialspoint.com

This is a very good website for learning any language or computer science courses. They are arranged very well, and have fantastic tutorials with lots of examples. They are based in India, and what's impressive is that they have covered almost everything in their vast tutorials library.

2. Geeks For Geeks => https://www.geeksforgeeks.org

This is another excellent website for learning anything computer science related. Although it says it's for geeks, I've found that their tutorials are very simple for beginners to learn. What I like is that they have divided their tutorials into different sections based on complexity, so you can just learn what suffices you. One shortcoming is that their library is not as vast as that of Tutorials Point, but they do have tutorials for all popular languages that we care about.

3. Digital Ocean => https://www.digitalocean.com/

This is not really a tutorials website, but a site for selling products. However, I bumped into it while trying to find a good tutorial on Javascript, and was amazed by the quality of the material. There is a tutorials section on this site, which is mainatined by a very active community. It has about 4K tutorials.

https://www.digitalocean.com/community/tutorials

It may be hard to find what you are looking for, since searching for something like "javascript" returns about 400 tutorials. However, what I've found is that they have tutorial "series", and depending on who wrote it, they may provide you the best tutorial out there. For ex, searching for html, shows me a "Series: How to build a website with HTML" => this is what you want to read. You need to read the whole series from start to end, so that you get the whole tutorial.

Conclusion: I'll add more websites as I come across more of them. There are some hugely popular websites as www.w3schools.com, or a language's official website, but most of the times that contain great reference material for the language, but don't really have great tutorials. You need to look elsewhere most of the times, and once you have some basic idea of a language, you can come to these official websites, and they will make a lot more sense.

The main thing to remember is not any one website has best tutorials for everything. Also, depending on who wrote it, the quality of tutorials may vary. Some are very good writers, and you might want to stick to tutorials of those writers on a given website. However, what I've found is that these websites try to maintain a consistent  writing style, so that's good.

 

 

 

 

software tools and packages:

Under GNU/Linux system, there are lot of software utilities and tools available. All of these are open source and are a better alternative than anything else out there. GNU site maintains these.

Link: https://www.gnu.org/software/software.html

A lot of these GNU packages were already covered under Linux cmds section. GNU packages like less, grep, tar, gzip, readline, time, etc are used so commonly, that they seem like Unix cmds. But in fact they are packages/software from GNU.

In this section, we'll cover many of these GNU packages, as well as other open source software that are not provided by GNU project. I've also included other software that are not strictly open source, but are widely used.

Tools for compiling:

  • gcc: Compiler for C
  • Make: GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files. 
  • Cmake: Alternative for make but not under GNU. Still a open source.

Languages:

  • sed: sed (stream editor) is a non-interactive command-line text editor. It is used to filter selected text/patterns from files. Very popular for using in scripts.
  • awk: It's replaced by gawk (GNU awk). It does similar thing as sed, and depending on pattern extraction to be done, awk may be more convenient. Use both awk and sed depending on your need.
  • bash: covered under shells. Other popular shell in csh, though csh is not under GNU.
  • R: R is a language and environment for statistical computing and graphics. 

Other utilities:

  • emacs: Very popular editor for editing files.
  • nano: another editor to replace pine or pico which were used as editors to read/write emails in Linux/GNU
  • gimp: GNU Image manipulation pgm. Very popular editor for editing images.
  • gnuplot: Used to generate 2D/3D plots of data. Inspite it's name, it's not associated with GNU, nor has GPL license. It's open source though, and widely distributed with all GNU/Linux distro.

 

 PHP Hypertext Preprocessor (PHP) : is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. PHP is the most popular scripting language used on servers. The php pgm to run is embedded in html code. When we don't want o have static html pages, we use php to generate dynamic html cod. This php script to generate dynamic webpage is run on server, and then once the html code is generated, it is sent to browser for display.

PHP is open source, and has C like syntax. It was created in 1994, and was originally called Personal Home Page (php). php is most used language for website coding, so it will suffice to learn just this language for building websites with dynamic content. If you want to build static website, just knowing HTML and CSS will suffice, but static websites are not easy to maintain, change, and are not used anymore (except for very small websites).

Official website for php. Here you can find lots of php doc and tutorial: http://php.net

 other good tutorial is from w3schools: https://www.w3schools.com/php/

Installation:

On linux mint, we'll use APT cmd to install php. Latest stable version f php is 7.2.PhP is cripting language, and so can scripts written in php with php interpreter. However, we want php to be able to connect to MySQL database, and as well as communicate with web server pgm to send it the contents to display. So, along with php, we install helper packages.

sudo apt install php libapache2-mod-php php-mysql => This installs php 7.2 + extra modules for it to talk to apache2 and mysql.

It installs these pkg on my system (All pkg installed are 7.2 version, and there are no other versions installed):

no versions: php, libapache2-mod-php, php-mysql, php-common => These pkg w/o version number actually point to 7.2 version

7.2 versions:  php7.2, libapache2-mod-php7.2, php7.2-mysq, php7.2-common, php7.2-cli, php7.2-json, php7.2-apcache, php7.2-readline => these pkg with version number 7.2 are the actual pkg installed.

which php => shows  /usr/bin/php as php binary location. This is a softlink to binary php7.2 stored here.

 php -v => shows php version num as 7.2

There are lots of php modules available. PEAR (PHP Extension and Application Repository is, collection of various useful PHP packages.

Running php:  There are various ways to run php. php is mostly used for server side scripting, where it geberates html o/p. It can also be used as cmd line script, to generate any kind of o/p. We will talk about few common ways to run php:

1. Interactive shell: on linux terminal, we can run php script with php interpreter. Just like any other scripting language, we can open php shell and run php interactively:

php -a => opens php interactive shell. Now we can type any php cmd on php cmd line terminal.

php> echo 2+3; => echo cmds work fine in php

5

php> exit

2. php file: we can have php script in a file, and pass that script to php interpreter, just like with other scripting languages.

test.php => create this file, and put below code in this file (.php extension is not necessary when writing code to run on php cmd line interpreter, it' needed only when running on webserver)

!#/usr/bin/php => 1st line indicates that interpreter used should be php

<?php => Any php code needs to be within "<?php" and "?>" tags. This tell the php engine to execute this code as php code. Anything outside this is treated as regular text, and php engine will just print it on screen as is. So if we omit these tags, php code will not execute at all and will just output the code on screen. It's important to have no space in these tags "<?php" and "?>", (i.enot like "<? php") or else they are not recognized as valid tags. Note: these tags were not needed in interactive shell, as php understands that it'sinteractive session, so every code entered is valid php code.

echo "Hello \n"; => simple echo stmt

phpinfo(); => This is a very useful function provided by php, which provides a lot of info abut php engine that was used to run this script. It is also used to validate if php is installed correctly and is running fine.

?>

any garabge text =>Anything written outside php tags is printed as is on screen. php engine doesn't even look at this and ignores it completely (as it's outside the php tags)

Now, after saving the script, change the permission to executable => chmod 755 test.php

./test.php => prints "Hello". If the 1st line (!#/usr/bin/php) in php file above is omitted, then we need to type "php test.php"

3. webserver script: We can have php file that we can pass to a webserver. Once php is installed on your machine, apache webserver on same m/c is able to access it, w/o doing anything more. The server finds out that this file needs to be interpreted by PHP because we used the ".php" extension, which the server is configured to pass on to PHP. So, .php extension is very important here, as w/o that, the webserver won't know what to do with this file. php files can have regular html code or any text in it. php parser looks for php code inside php tags, and does whatever is asked of it. Parsing in this manner allows PHP to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. Then it returns the final generated file (replacing code within php tags with the output of the script) to server engine, which sends it to the browser.

If we have apache installed, we'll see a default file here: /var/www/html/index.html

IF we open browser, and type "127.0.0.1" in the browser address, we'll see default ubuntu page show up (see in apache tutorial section). Now if we put some other file here named test.php, and access it via addr "127.0.0.1/test.php" in the browser, it will be sent to apache server, which will pass it to php engine (since it has .php extension), We can copy below code in test.php file (we'll need to open this file preceeding it with sudo, since only root has permission to edit in this dir).

sudo emacs /var/www/html/test.php

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>

  <p>** Outside : before php **</p>
 <?php echo '<p>Hello World</p>'?> 

  <p>** Outside : after php **</p>
 </body>
</html>

 Now, on accessing addr "127.0.0.1/test.php", we will see "Hello World" printed on browser, as the php code has been parsed by php engine. We'll also see text with "** ... **"  that's outside php tags.

PHP syntax: We'll be talking about php syntax when used as webserver script. Just like any other language, php file is parsed by parser, which parses tokens and looks for var defn, operators, std keywords, functions, etc. language defines data types as number, string, etc. Variables store different data, belonging to one of these data types. We have operators to operate on these var. We have conditional stmt to get pgm to take diff execution paths.

1. Any PHP file needs to have a .php extension for webserver to recognize it and pass it to php interpreter. php file can have any text in it, but anything within php tags (<?php and ?>) needs to be valid php code, and that is the only code that will be parsed by the php engine. Php syntax refers to php code inside these tags.

2. If php contains only php code, and nothing else, then closing php tags (?>) can be omitted.

3. Each php stmt ends with semicolon ";", (except for the tags. tags imply continuation of stmt, so no ; used. same for stmt like "if else" which are 1 stmt, so no ; used except inside { } which may have multiple stmt in them).

3. comments: C style (// for single line and /* ... */ for multi line) of comments supported. PHP also supports scripting language type single line comment (starting with #).

4. case sensitivity: php variables are case sensitive, but std keywords, class, functions are not case sensitive.For ex, $book and $Book are different, but "when" and "WhEn" are same.

5. whitespaces in php serve as a separator for tokens, so that the interpreter can parse the file for tokens. However, it seems tolerant of non-whitespaces also (i.e ( a < b ) and (a<b) both seem to work ).Not sure, how lenient it is with whitespaces, but it's a good idea to always have whitespaces.

6. variables: variables are specified with $ sign in front of var name. var name can only contain alphanumeric char and a underscore (A-Z, 0-9, a-z, _), and must can't start with a number. variables are case sensitive. We do not specify data type (i.e int, char, etc) of var, php automatically assigns it based on it's value. Thus, it's called loosely typed language, and is similar to almost all other scripting languages, which never assign data types. However, in php 7, data type declaration can be added using "strict" keyword.

php supports following data type:

  • string: sequence of char inside single or double quotes. ex: $str = "my name"; MAny builtin func can be used to manipulate string. ex: strlen("Hello world!"); => returns length of string as 12.
  • integer: $x=435; php func var_dump($x) returns var type and value.
  • float: $x=4.23; php func var_dump($x) returns var type and value.
  • boolean: 2 values "true orTRUE" and "false or FALSE". $x=true; NOTE: there is no quotes around this (As $x="true" makes $x a string, and not boolean). booleans are usedin conditional stmt
  • array:stores multiple values in single var.ex: $cars = array("Volvo","BMW","Toyota"); $cars[0] refers to "volvo", so on. can also be assigned as $cars[2]="BM", Many func available to manipulate arrays.ex: count($cars), sort($cars), etc.
    • associative arrays: similar to perl associative arrays, used to store key/value pair. ex: $age = array("Jim" => "25", "Joe" => "35"); now $age['Jim'] refers to value "25". This can also be assigned as $cars['Joe']="maruti"; We can loop thru associative arrays using foreach. function print_r($age) explained below, will print array's all key/value pairs w/o going thru "for" loop for each array element.
  • object: An object is a data type which stores data and information on how to process that data. We use "class" for this, just like in other Object oriented languages.
  • NULL: Null is a special data type which can have only one value: NULL. Any variable is created without a value is automatically assigned a value of NULL. ex: $x=NULL;

The scope of var (i.e places where it can be called or referenced) is of 3 types:

  • global: var declared outside of any function have global scope, and can be accessed only outside the function (so not truly global, as var not available within the function). However, re declaring these var with "global" var inside the function allows these var to be used within the function.
    • superglobals: there are various predefined superglobal var, that can be accessed anywhere on php code.There are lots of them, and each of these var store useful info in an associative array. ex: $_SERVER superglobal => holds information about headers, paths, and script locations. ex: $_SERVER['HTTP_HOST'] => Returns the Host header from the current request
  • local: var declared within a function have local scope, and can only be acccessed within that function.
  • static: this is still a local var declared within a func, but we can declare it to be static, which will prevent the var from getting deleted when exiting the func. So, next time func is called, value of the var from last time is still preserved.

7. operators: php divides operators in following groups:

  • arithmetic operators: used on numerical values. +, -, *, /, % (modulus), ** (exponentiation)
  • assignment opeartors: used to assign values to var. =, +=, -=, *=, /=, %= (a +=b is same as a=a+b)
  • comparison operators: ==, === (both equal and same type), !=, !==, <, >, <=, >=
  • increment/decrement operator: ++$x (pre increment, increment $x first, then return $x), $x++ (post increment, return $x first, then increment $x), --$x, $x--
  • logical operators: and (same as &&), or (Same as ||), xor, ! (not). ex: $a = $x and $y; $b = !$a; $c = $a || $b;
  • string operators: . (Concatenation), .=(conctenation assignment, $a .= $b is same as $a = $a . $b). ex: $c = $a . $b (concatenates string $a and $b, to form new string $c, with no space in b/w $a and $b)
  • array operators: +, ==, ===, !=, !== these operators same as comparison but apply to array and check key/value pair match. + implies union of 2 arrays
  • conditional assignment: ?= (if else) same as in C language

8. conditional stmt:

  • if else: ex: if ($cond != 0) { echo "name"; $c=$a; ... }. if-elseif: ex: if (..) { ... } elseif (...) { ... } else { ... } => these don't have semicolon as if else are just 1 big stmt. Inside { }, we should have ; for each stmt. else, elseif are all optional.
  • switch: to select one of many blocks of code
  • loops: while, do while, for, foreach

9. display: various inbuilt functions avalable to display on scrren. i.e. echo(), print(), print_r().

echo and print are used to display values/text. Both can be used with or w/o parentheses (i.e print "a"; or print("a");). echo works same way as linux echo. ex: echo "My $name"; echo "me" . $name . "and"; print syntax same as echo. One diff is that print returns a value of 1, while echo doesn't return any value. So, print can be used in expressions. Both stmt can contain html markup code in them (i.e print "<b> Hi </b>";). prinrt_r() is used to display values in nice human readable format. print_r can be used to display associative arrays, w/o going thru "for" loop. eg print_r($age); where $age is an associative array.

 10. functions: besides the built in functions, we can define our own function using "function" keyword. ex: function myfunc ($a) { ...return $c; }. Now myfunc can be called as myfunc(5); or $a=myfunc("hello"); Functions may or may not have a return value.

php forms:

  • $_REQUEST
  • $_POST
  • $_GET']

 

Php cookies and sessions: good link here: http://shiflett.org/articles/the-truth-about-sessions

cookies:

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Cookie is a human readable text file. Each time the same computer requests a page with a browser, it will send the cookie too. The server reads these cookies and determines various info about the user stored in cookies. These cookies need to be stored in client's computer by the server in the very beginning. With PHP, you can both create and retrieve cookie values. It is upon the browser to accept or decline cookies. Some websites demand that you agree to store cookies, or they refuse to show you the webpage.

setcookie(name) => this func sets cookie name. other optional parameters as cookie value, expiry time, etc may be set too, If expiry time not set, then cookie destroyed on closing the browser or that tab of browser.

ex: setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); This has expiration time in future = 86400 * 30 sec = 30 days from current time. (since 1 day = 86400 seconds). To delete a cookie, set it's expiration time in past. setcookie should be the very first thing to do in any php file, before we write out any html code using <html> tag.

superglobal var $_COOKIE stores the value of cookie. i.e $_COOKIE[$name] gives the value of cookie with name $name.

ex: if ( isset($_COOKIE[$cookie_name])) { echo "Value is: " . $_COOKIE[$cookie_name]; } //function isset checks if $_COOKIE[name] is null or has  any value

Note: The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received (to prevent URLencoding, use setrawcookie() instead).

how cookies work:

So, the way cookie's work, is when a browser calls www.xyz.com/index,php, it causes the webserver to process index.php file. index.php has setcookie() function before any <html> tag in the file. This setcookie function is written as some conditional stmt, so that if that request is coming from a client computer for the first time, only then this setcookie func is called. The cookie values are sent by client, in the HTTP header of the request (header has lot of other info also, besides cookie info). $_COOKIE var extracts and stores these cookie values. Depending on whether the header sent by client has "cookie values" in it or not,  $_COOKIE may contain these values or be empty.

ex: if (count ($_COOKIE) == 0) { setcookie ... } else {read cookie values from request sent by browser} => this cmd sets cookie only if number of cookies stored in $_COOKIE var is 0. This code sits before any <html> tag.

This causes the cookie to be set if it was already empty, so that the next response sent by server (which is actually the response to this request sent by client),  will include these cookie name/value pairs in the HTTP header of response. NOTE: $_COOKIE stores cookie values that come in the request header of client. If client header doesn't have these cookie values in it, $_COOKIE will be null. Several copies of index.php may be running on the server at the same time, since many clients may be connecting to the same server, but each of them has their own copy running, and stores the cookie value received from header of client response in superglobal var $_COOKIE.  So, $_COOKIE value is unique for each client connection, even though the same index.php script is running for all clients. If there is some other script as welcome.php running on server, it will have it's own unique values stored in $_COOKIE depending on what the browser sent it. If browser sent same cookie value for other scripts, then $_COOKIE will have same value for other script too.

We can check the request header sent by the client by opening "web developer" in the "open menu" icon on far right of "firefox" web browser. Within "web developer", we will see "storage inspector".  Clicking this will open a new section on bottom of that firefox page. Here we will see a lot of tabs along with "storage" tab. Clicking on storage tab will show couple of sections on right side, one of which is "ccokies". Clicking on "cookies" will show all the cookie values stored by that website on this computer.

If we click on "network" tab instead of "storage" tab, we'll see all the http request/response sent/received by the user computer, time it took, etc. This request/response has multiple lines. First line is the request/response line. 2nd line is required header "Host". After that we can have multiple optional headers. One of such optional headers is "Cookie" for request, and "Set-Cookie" for response. A very good site explaining this is here: http://shiflett.org/articles/the-truth-about-sessions. If we click on the latest http request sent by the browser (shown at the bottom of all requests in the "network" tab of firefox), it will show the http request header sent by the client, as well as the http response header received by the client (which was sent by the webserver after processing the http request sent by the client). In request header, we should see a "Cookie" as one of the headers being sent. It should have name/value pair, if the cookie is set on client's m/c already. If the client m/c is visiting this website for first time, then this info may be absent from http request header. Similarly in the response header sent by webserver, we'll see a "Set-Cookie" header being sent (if setcookie function was called in the php script run by the server, for that request). If setcookie function was not called, then this header will be absent from response. This is a very good way to debug and understand how cookies are being sent and received.

Sessions:

Once the cookie name/value pair is set on user m/c, the cookie is stored on user's computer for ever, until it expires. Sometimes, we do not want the info to be stored for ever. We want info to be stored when the user visits our webserver using a browser, and remain stored, until the user closes the browser or that tab of browser. Also, cookie have another problem, where cookies are stored on user's computer, which makes it a security hole. Cookies do not allow info to be accessed across all pages of a website (or they have to be passed individually to each page, and we have little control on which pages can or cannot access these cookie variables).

These issues are resolved via a session. sessions are similar to cookies in many aspects. session is basically treating website as an application started by a particular user. It stores info related to that user across all pages of a website, so that all pages can uniquely identify the user. It does this by setting a user-key cookie on the user's computer. This cookie name is "PHPSESSID" and it has value that looks something like this: 765487cf34ert8dede5a562e4f3a7e12. It's expiry is set to "session" (i.e expires when user closes the browser or tab). Then, when a session is opened on another page, it scans the computer for this cookie. If there is a match, it accesses that session, if not, it starts a new session.

A session is started with the session_start() function. This causes cookie "PHPSESSID" to be stored with a large random value on user's m/c. This cookie is just like any other cookie, and can be read via $_COOKIE["PHPSESSID"]. IThis cookie is used to uniquely identify the connection of this website to the user's m/c. f this cookie was already set, then session_start() function doesn't set it, but just reads it. Once session_start() function is called, and a session has been started, other session var can now be set. Session variables are set with the PHP global variable: $_SESSION (i.e $_SESSION["user"] = "Matt"); Now we can access this session var "user" in any other script too, by reading $_SESSION["user"]. session_start() function needs to be put before any <html> tags. It's put in all the pages, wherever we need to access these session var. As explained above, session_start() doesn't always start a new session (it starts new session only if it finds no user-key match on reading PHPSESSID cookie),

PHP session expire on closure of window/tab of browser. They also have a default timeout limit of 1440 sec (24 min). So, if session is inactive for more than 24 min, the session var $_SESSION gets unset (i.e it stores nothing). Note that the cookie PHPSESSID still remains valid, and can be read in any php script even after timeout, as long as the browser/tab is not closed.

ex: Below we show 2 scripts. Both scripts can access the same session var.

script_1.php

<?php session_start(); ?> // PHPSESSID cookie is set with random key, if not already set

<html>

<body>

<?php $_SESSION["userName"] = "raj"; // $_SESSION superglobal var is set in this script, but is accessible from any script. This var is set to this value only for this PHPSESSID cookie.

print_r($_SESSION); ?>

</body>

</html>

script_2.php

<?php session_start(); ?> // PHPSESSID cookie is not set here, since the script finds this cookie on user m/c already set. So, it reads the cookie session value, and on a match, starts the same session as in script_1.php

<html>

<body>

<?php

if (isset($_SESSION['$userName'])) { echo "Your session is running " . $_SESSION['$userName']; }

?>

</body>

</html>

 

sql database:

php allows to connect to and manipulate database. We'll talk about mysql database connections via php scripts. Read mysql tutorial section before reading this section. Before php5, MySQL extension was used to connect to MySQL db, but from php5 onwards, MySQLi (MySQL improved) and PDO (PhP data objects) extensions provided (MySQL was deprecated in 2012). MySQLi can only connect to MySQL db, but PDO can connect to many other db too. However, PDO is more complex, so we'll concentrate on MySQLi only.

MySQLi is object oriented, but supports procedural calls too (i.e can work like a function call too, for folks who don't like to code in object oriented format). We'll focus on using mysqli as a function as that's easier to learn.

The PHP functions for use with MySQL have the following general format −

mysqli_function(value,value,...);

The second part of the function name is specific to the function, usually a word that describes what the function doest The following are two of the common functions:
$connect = mysqli_connect($servername, $username, $passwd); //connects to a db. It has return value of link identifier of mysql db server on success, and FALSE on fail. This link identifier is used to perform any operation on this mysql db server
mysqli_query($connect,"SQL statement"); //performs operations on db

NOTE: we can connect to mysql server only with the username who is listed as user in "user" table of "sql" database. If we haven't added any user to mysql server previously,
then root is the only user allowed. However, if I try to connect to mysql from php script as "root" user, I get an "access denied error" for user "root@localhost".So, add another user to
php, and connect as that user.

ex: The php script below very useful to check if your browser can connect to mysql db on a server. This should be the first script to run on any 3rd party webhost server, on which you have your website and mysql db hosted.
<?php
$servername = "localhost"; //name of server, if running on same m/c, use localhost
$username = "username"; //any valid username other than "root"
$password = "password"; //password for that user

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection.
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
 
//create database
$sql = "CREATE DATABASE myDB";
if (mysqli_query($conn, $sql)) {
    echo "Database created successfully";
} else {
    echo "Error creating database: " . mysqli_error($conn);
}
 
//create/insert etc .. any sql cmd can be issued to this db
$sql = "CREATE TABLE MyGuests ( ..., )"; //or "INSERT INTO ....,

if (mysqli_query($conn, $sql)) {
    echo "operation successful";
} else {
    echo "Error in operation: " . mysqli_error($conn);
}
 
//queries on db, requires other functions (as mysqli_num_rows(), mysqli_fetch_assoc(), etc)  to process and display results of query
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}
mysqli_close($conn);

?>
---------------------------------------------
 

 

 

Artificial Intelligence (AI):

branch of computer science with goal of making computers or machines as intelligent as humans. John McCarthy is called the father of AI. He demonstarted 1st AI pgm in 1956 at CMU. AI is dominant in fields of gaming (chess, poker, go), natural language processing (NLP, which understands natural language spoken by humans), vision systems (which can comprehend visual images, video), speech recognition, handwriting recognition, robotics, etc.

AI can be classified in 2 - narrow AI, and general AI. narrow AI refers to use of AI for a narrow purpose as self driving car, smart speaker, etc, while general AI refers to doing anything that a human can do.

AI is basically supervised learning, where after the learning process, a system can be made smart enough where it can produce correct o/p for any given i/p. There is so much interest in AI today, is because traditional AI didn't perform better even when the amount of training data grew. But now with specific branches of AI, we can scale AI performance with the amount of data, i.e more the data, higher the accuracy of prediction. This is specifically true for neural nets, and more so for deep neural nets, which are just one of the approaches of AI.

Machine learning (ML):

AI started as wide field, with thousands of approaches to achieve this intelligence in m/c. All these approaches were being worked until 1980s. However, then a particular subset of AI called machine learning (ML) began to flourish, as it showed much greater promise. It was the practice of using algorithms to parse data, learn from it, and then make a determination or prediction about something in the world. It's algorithmic approaches included decision tree learning, inductive logic programming. clustering, reinforcement learning and Bayesian networks among others. One of the very best application areas for machine learning for many years was "computer vision", though it still required great deal of hand-coding. "computer vision or image detection" was the field of identifying images and videos to make sense of that image. However, it never achieved the goal of general AI, at best it was narrow AI, and even then it was very error prone.

Neural Network (NN) or artificial neural networks (ANN):

A particular algorithmic approach of machine learning, called artificial neural networks (ANN) (or simply NN) had been a topic of research for several decades. They were based on analogy of how human brain works. However, they were mostly shunned by AI research community as never showed much promise of intelligence. The problem was even the most basic neural networks were very computationally intensive, it just wasn’t a practical approach. However, in 2000 as super computers got more powerful, this started to change. ANN were able to learn from a large set of data, and get good results. Previous algo in ML saturated in how well they performed, even after more and more data was used to train them. But ANN scaled with data, and allowed the error rate to keep on going down, as more and more data was used to train them. In 2001, for the first time, human face detection was possible from images. This algo from research came into a product in 2006, when camera started having face detection technology in realtime. This was a major accomplishment. However, with ANN, even these powerful computers weren't able to unleash full power of ANN as they weren't able to handle massive computation. 

Deep learning or Deep Neural network:

Then in mid 2000, the field of ANN got major breakthrough. GPU started getting deployed for doing massive computation needed for ANNs. GPU do a lot of computation in parallel, as compared to CPU which do mostly serial computation. In 2012, Andrew Ng at google (previously a professor at Stanford) took these neural networks, and essentially made them huge, increased the layers and the neurons, and then ran massive amounts of data through the system to train it. In Ng’s case it was images from 10 million YouTube videos. Andrew Ng put the “deep” in deep learning, which describes all the layers in these neural networks. He ran a neural network trained using deep learning algo running on 16,000 CPU cores, that learned to recognize cats after watching only youtube videos, and w/o ever having been told what a "cat" is. For the first time, the promise of "intelligence" was realized. Deep learning is one of the methods applied to ANNs, and can be considered a subset of ANN. It just increases the depth of NN, and by doing that, it makes them deep. This makes NN perform exponentially better. Instead of deep NN, you can design shallow NN too if you have limited computed resource, but they do not perform that well (early ANN were shallow).

Convolution neural network (CNN):

There are various classes of ANNs. The class used in deep learning, that we saw above, is called deep neural network. There are various classes within deep neural network. One that is most commonly applied to analyze images and videos is called CNN. In 2010, ImageNet started in image classification challenge. The error rate in 1st 2 years hovered around 25%. In 2012,  an algorithm dropped error rate from 25% in previous years to 15%. This magical algorithm was CNN, and it started the runaway success of CNN. CNN have since dominated the field, and effort every year has been to improve CNN, rather than spending effort/dollar on alternative algo. We will only focus on CNN from now on. The term "convolution" indicates that the network employs a mathematical operation called convolution. Convolution is a specialized kind of linear operation. Convolutional networks are simply neural networks that use convolution in place of general matrix multiplication in at least one of their layer. Even though CNN is a class within deep learning which itself is a subset of ANN, they have all become synonymous with deep learning, and the 3 terms are used interchangeably (DL/ANN,NN/CNN).

One of the reasons CNN are so popular is that they use relatively little pre-processing compared to other image classification algo. This means that the network learns the filters that in traditional algorithms were hand engineered. This independence from prior knowledge and human effort in feature design is a major advantage.

One very good explanation of CNN is here: https://ujjwalkarn.me/2016/08/11/intuitive-explanation-convnets/

Other link here (read both parts 1 and 2): https://adeshpande3.github.io/adeshpande3.github.io/A-Beginner's-Guide-To-Understanding-Convolutional-Neural-Networks/

3Blue1Brown video series on Youtube are absolutely amazing (4 chapters on NN series): https://www.youtube.com/playlist?list=PLZHQObOWTQDNU6R1_67000Dx_ZCJB-3pi

This site is one recommeneded by 3B1B. It's a completely free online Book with 6 chapters: http://neuralnetworksanddeeplearning.com/index.html

You should look at Andrej Karpathy website: https://karpathy.ai. Lots of fun and life learning stuff. This course by Andrej Karpathy on coding your own GPT (videos build up from basics): https://karpathy.ai/zero-to-hero.html

There are video lectures by Prof Andrew Ng (from Stanford) on www.coursera.org

This is a very good starting point for AI, and I would base my next sections on his lectures on Coursera.