Home > Programming > Shell Programming



Korn Shell (ksh) Programming

Sort Desciption:

Korn Shell (ksh) Programming A tutorial by Philip Brown Copyright 2002 This is the top level of my



Content Inside:

SHELL Programming (2) TA: Guoli Li Agenda •Basic Shell Programming -Some commands useful with scripts -Variables -Flow control •Example 1 -Rename files •Example 2 -Classical recursive factorial Useful Commands •echo : Built-in command display message to standard out •sleep : Command causes execution to stop for a specified number of seconds •read : Built-in command reads data into variable from standard in •expr : Evaluates an expression and output its value •false : Built-in command always return false condition •true : Built-in command always return true condition Variables •var=value Define a variable •var="" Define a variable as null •var=`command` varis set to output of command •$var Value of variable var -"$var"is null if variable is undefined -${var}avoids confusion when concatenating with text Flow Control •IF -If   command Test return code of command -If command1 && command2 -If command1 || command2 •IF/THEN/ELSE or IF/THEN/ELSEIF -if condition then statements… [else statements…] fi Flow Control -if condition then statements… [elif condition … then statements… [else] statements…] fi •Conditions -e.g.,  string1 = string2   ( != ) -e.g., num1 -eqnum2  (-ne, -lt, -le, -gt, -ge) Flow Control •FOR -for  name [in list ] do statements done -for variable = start to end do statements done Flow Control •WHILE/UNTIL -while condition do statements done -until condition do statements done Example 1 •Suppose that you have some mp3 files in current directory with meaningless names, and you want to number they sequentially. Solutions #!/bin/sh track =1; for file in *.mp3 do mv"$file""${track}.mp3" track=`expr$track + 1` done Example 1-1 #!/bin/sh track=1; for file in *.mp3 do if [ $track -lt10 ] then mv"$file" "0${track}.mp3" else mv"$fi ...

Source:


add to Google Reader add to Google Bookmark add to bloglines add to newsgator add to FURL add to digg add to webnews add to Netscape add to Yahoo MyWeb add to spurl.net add to diigo Bookmark newsvine Bookmark del.icio.us Bookmark @ SIMPIFY Bookmark MISTER WONG Bookmark Linkarena Bookmark icio.de Bookmark oneview Bookmark folkd.com Bookmark yigg.de Bookmark reddit Bookmark StumbleUpon Bookmark Slashdot Bookmark blinklist Bookmark technorati add to blogmarks add to blinkbits add to ma.gnolia add to smarking.com add to netvouz add to co.mments add to Connotea add to de.lirio.us

 

Related Files

basic shell programming

Filed under: Programming and Shell Programming
bash derives much of its programming functionality from shell variables. Weve ... builtin variables that are vital to shell programming. ...

Unix Shell Scripts

Filed under: Programming and Shell Programming
that file is called shell script language. Like other programming languages it has variables and flow control. statements (e.g. ifthenelse while for ...

UNIX Shell Programming

Filed under: Programming and Shell Programming
Page 1 of 1 ITC_UNIXsp ExecuTrain Course Outline UNIX Shell Programming IT0001 3 Days Description Students learn to read, write, and debug shell scripts, thus increasing ...

Automated testing using Shell Scripting

Filed under: Programming and Shell Programming
Advanced Bash scripting guide from The Linux Documentation Project (TLDP). Unix Shell Programming by Yashavant Kanetkar BPB Publication. ...

Shell Programming

Filed under: Programming and Shell Programming
This training in Shell Programming is designed for. administrator to create and debug shell scripts so as to. automate routine tasks. ...