Search This Blog

Tuesday, August 28, 2012

Unix Shell Learning


  1. Create aliases
    • Know your shell first;
      • # echo $SHELL
    • If output = '/bin/csh', type 
      • # echo ls   'ls -al' >> ~/.cshrc
    • Else if o/p = '/bin/bash', type 
      • # echo 'ls = 'ls -al' >> ~/.bashrc
    • And then type
      • # source ~/.cshrc

Thursday, April 12, 2012

Argument List in main() function


main(int argc, char** argv)
(The syntax char** argv declares argv to be a pointer to a pointer to a character, that is, a pointer to a character array (a character string)--in other words, an array of character strings. You could also write this as char* argv[]. Don't worry too much about the details of the syntax, however--the use of the array will be made clearer below.)
When you run a program, the array argv contains, in order, all the information on the command line when you entered the command (strings are delineated by whitespace), including the command itself. The integer argcgives the total number of strings, and is therefore equal to equal to the number of arguments plus one. For example, if you typed
 a.out -i 2 -g -x 3 4
the program would receive
 argc = 7
 argv[0] = "a.out"
 argv[1] = "-i"
 argv[2] = "2"
 argv[3] = "-g"
 argv[4] = "-x"
 argv[5] = "3"
 argv[6] = "4"