When I started my career in IT field, I have landed into windows world, as I know that no companies give chance to a fresher to work on production Linux/Unix servers. Its a good experience to work on DOS scripts(aka Batch programming). There are many similarities/differences/advantages/disadvantages between Batch programming and Shell scripting. Lets see what they are.
Similarities
Sl.No | Batch programming | Shell script |
1 | Sequential execution of group commands in a batch file | Sequential execution of group command in shell scripts |
2 | Can read inputs from users | Can read inputs from users |
3 | Has control structures such as for, if, while, switch for better automating/scripting | Has control structures such as for, if, while, switch for better automating/scripting |
4 | Supports advanced features such as Functions and Arrays | Supports advanced features such as Functions and Arrays |
5 | Supports regular expressions(using findstr) | Supports regular expressions |
6 | Can include other programming codes such as perl(ie.. in middle of dos script we can include some other programming language code for effective scripting to get our desired output) | Can include other programming codes such as Perl, AWK, SED etc. |
Differences
Sl.No | Batch programming | Shell script |
1 | Lack of richness of tools/commands | Have good number of tools(as of my knowledge there are more than 75000 commands in Linux/Unix) |
2 | Supports only one vendor(i.e. windows) | Supports for number of vendors such as Sun/apple/IBM AIX/HP-UX/GNU Linux etc. |
3 | No other variants for DOS | There are number of variants such as bash, ksh, csh, zsh etc.. |
4 | Low capabilities of integrating with other programming code in batch scripting | Good capabilities of integrating other programming code in shell script |
5 | Cannot handle complex regular expressions | Can handle complex regular expressions. |
6 | A batch file should always end with .bat | There is no such concept like file extension, but a shell script file permission should be set to executable. |
7 | To execute a batch program just enter the file name at CLI | To execute a shell script, here are the ways to execute it 1)chmod +x shellscript.sh;./shellscript.sh 2)sh shellscript.sh |
Good article on how to convert your Batch program to a Shell script.
http://tldp.org/LDP/abs/html/dosbatch.html
http://tldp.org/LDP/abs/html/dosbatch.html