summaryrefslogtreecommitdiff
path: root/Unix_Concepts_And_Applications_by_S_Das/14-Essential_Shell_Programming.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Unix_Concepts_And_Applications_by_S_Das/14-Essential_Shell_Programming.ipynb')
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/14-Essential_Shell_Programming.ipynb1434
1 files changed, 1434 insertions, 0 deletions
diff --git a/Unix_Concepts_And_Applications_by_S_Das/14-Essential_Shell_Programming.ipynb b/Unix_Concepts_And_Applications_by_S_Das/14-Essential_Shell_Programming.ipynb
new file mode 100644
index 0000000..3e191b7
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/14-Essential_Shell_Programming.ipynb
@@ -0,0 +1,1434 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 14: Essential Shell Programming"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.10: Program_10.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 10 : Show the use of while loop and sleep \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#! /bin/sh'\n",
+"li(2)='# monitfile.sh:Waits for a file to be created'\n",
+"li(3)='#'\n",
+"li(4)='while [ ! -r invoice.lst ] # While the file invoice.lst cannot be read'\n",
+"li(5)='do '\n",
+"li(6)=' sleep 60 # sleep for 60 seconds'\n",
+"li(7)='done'\n",
+"li(8)='alloc.pl # Execute this program after exiting the loop'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:8\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lst(1)='@echo off'\n",
+"lst(2)='cls'\n",
+"lst(3)='echo This program keeps on looping until the file invoice.lst if exists is readonly'\n",
+"lst(4)='echo Later it executes the script alloc.pl if it exists once it if readwrite type '\n",
+"lst(5)=':loop'\n",
+"lst(6)='set perm=r'\n",
+"lst(7)='if '+ascii(34)+'%perm%'+ascii(34)+'='+ascii(34)+'-'+ascii(34)+' goto endloop'\n",
+"lst(8)=' ping -n 60 localhost>null'\n",
+"lst(9)=' if exist invoice.lst for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'invoice.lst'+ascii(39)+') do set att=%%~aA&&set perm=%att:~1,1%'\n",
+"lst(10)='goto loop'\n",
+"lst(11)=':endloop'\n",
+"lst(12)='echo Executing alloc.pl if it exists' \n",
+"lst(13)=' if exists alloc.pl start alloc.pl'\n",
+"lst(14)=' pause>NUL'\n",
+" \n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:14\n",
+" mfprintf(v,'%s\n',lst(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.11: Program_11.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 11 : Show the use of positional parameters in shells \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='2233|a.k.shukla |g.m. |sales |12/12/52|6000'\n",
+"i=i+1;f(i)='9876|jai sharma |director |production |12/03/50|7000'\n",
+"i=i+1;f(i)='5678|sumit chakrobarty|d.g.m |marketing |19/04/43|6000'\n",
+"i=i+1;f(i)='2356|barun sengupta |director |personnel |11/05/47|7800'\n",
+"i=i+1;f(i)='5423|n.k. gupta |chairman |admin |30/08/56|5400'\n",
+"i=i+1;f(i)='1006|chanchal singhvi |director |sales |03/09/38|6700'\n",
+"i=i+1;f(i)='6213|karuna ganguly |g.m. |accounts |05/06/62|6300'\n",
+"i=i+1;f(i)='1265|s.n. dasgupta |manager |sales |12/09/63|5600'\n",
+"i=i+1;f(i)='4290|jayant Choudhary |executive |production|07/09/50|6000'\n",
+"i=i+1;f(i)='2476|anil aggarwal |manager |sales |01/05/59|5000'\n",
+"i=i+1;f(i)='6521|lalit chowdury |director |marketing |26/09/45|8200'\n",
+"i=i+1;f(i)='3212|shyam saksena |d.g.m |accounts |12/12/55|6000'\n",
+"i=i+1;f(i)='3564|sudhir Agarwal |executive |personnel |06/07/47|7500'\n",
+"i=i+1;f(i)='2345|j.b. saxena |g.m. |marketing |12/03/45|8000'\n",
+"i=i+1;f(i)='0110|v.k. agrawal |g.m. |marketing |31/02/40|9000'\n",
+"n=i\n",
+"printf('\n\n$ cat emp.lst # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('emp.lst','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#! /bin/sh'\n",
+"li(2)='# emp6.sh -- Using a for loop with positional parameters'\n",
+"li(3)='#'\n",
+"li(4)='for pattern in '+ascii(34)+'$@'+ascii(34)+' ; do # decided not to use $* in the previous section'\n",
+"li(5)=' grep '+ascii(34)+'$pattern'+ascii(34)+' emp.lst||echo '+ascii(34)+'pattern $pattern not found'+ascii(34)\n",
+"li(6)='done'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:6\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lst(1)='@echo off'\n",
+"lst(2)='set b=0'\n",
+"lst(3)='for %%x in (%*) do set /a b+=1'\n",
+"lst(4)='set i=2'\n",
+"lst(5)='findstr '+ascii(34)+'%1'+ascii(34)+' emp.lst>res'\n",
+"lst(6)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'res'+ascii(39)+') do set siz=%%~zA'\n",
+"lst(7)=':loop'\n",
+"lst(8)='if %siz% equ 0 echo Pattern %1 not found&&goto incr'\n",
+"lst(9)='echo Search results for pattern %1'\n",
+"lst(10)='echo ------------------------------------------------'\n",
+"lst(11)='echo.'\n",
+"lst(12)='type res'\n",
+"lst(13)=':incr'\n",
+"lst(14)='if %i% gtr %b% goto endloop'\n",
+"lst(15)='shift /1'\n",
+"lst(16)='del res'\n",
+"lst(17)='findstr '+ascii(34)+'%1'+ascii(34)+' emp.lst>res'\n",
+"lst(18)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'res'+ascii(39)+') do set siz=%%~zA'\n",
+"lst(19)='set /a i+=1'\n",
+"lst(20)='echo.'\n",
+"lst(21)='goto loop'\n",
+"lst(22)=':endloop'\n",
+"lst(23)='pause>NUL'\n",
+"lst(24)='del res'\n",
+" \n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:24\n",
+" mfprintf(v,'%s\n',lst(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.12: Program_12.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 12 : Show the use of shift arguments \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='2233|a.k.shukla |g.m. |sales |12/12/52|6000'\n",
+"i=i+1;f(i)='9876|jai sharma |director |production |12/03/50|7000'\n",
+"i=i+1;f(i)='5678|sumit chakrobarty|d.g.m |marketing |19/04/43|6000'\n",
+"i=i+1;f(i)='2356|barun sengupta |director |personnel |11/05/47|7800'\n",
+"i=i+1;f(i)='5423|n.k. gupta |chairman |admin |30/08/56|5400'\n",
+"i=i+1;f(i)='1006|chanchal singhvi |director |sales |03/09/38|6700'\n",
+"i=i+1;f(i)='6213|karuna ganguly |g.m. |accounts |05/06/62|6300'\n",
+"i=i+1;f(i)='1265|s.n. dasgupta |manager |sales |12/09/63|5600'\n",
+"i=i+1;f(i)='4290|jayant Choudhary |executive |production|07/09/50|6000'\n",
+"i=i+1;f(i)='2476|anil aggarwal |manager |sales |01/05/59|5000'\n",
+"i=i+1;f(i)='6521|lalit chowdury |director |marketing |26/09/45|8200'\n",
+"i=i+1;f(i)='3212|shyam saksena |d.g.m |accounts |12/12/55|6000'\n",
+"i=i+1;f(i)='3564|sudhir Agarwal |executive |personnel |06/07/47|7500'\n",
+"i=i+1;f(i)='2345|j.b. saxena |g.m. |marketing |12/03/45|8000'\n",
+"i=i+1;f(i)='0110|v.k. agrawal |g.m. |marketing |31/02/40|9000'\n",
+"n=i\n",
+"printf('\n\n$ cat emp.lst # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('emp.lst','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# emp7.sh: Script using shift -- Saves first argument;for works with the rest'\n",
+"li(3)='#'\n",
+"li(4)='case $# in'\n",
+"li(5)=' 0|1) echo '+ascii(34)+'Usage: $0 file pattern(s)'+ascii(34)+' ; exit 2 ;;'\n",
+"li(6)=' *) flname=$1 # store $1 as a variable before it gets lost'\n",
+"li(7)=' shift'\n",
+"li(8)=' for pattern in '+ascii(34)+'$@'+ascii(34)+' ; do # Starts iteration with $2'\n",
+"li(9)=' grep '+ascii(34)+'$pattern'+ascii(34)+' $flname || echo '+ascii(34)+'Pattern $pattern not found'+ascii(34)\n",
+"li(10)=' done'\n",
+"li(11)=' esac'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:11\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lst(1)='@echo off'\n",
+"lst(2)='set b=0'\n",
+"lst(3)='for %%x in (%*) do set /a b+=1'\n",
+"lst(4)='set i=3'\n",
+"lst(5)='set fille=%1'\n",
+"lst(6)='shift /1'\n",
+"lst(7)='findstr '+ascii(34)+'%1'+ascii(34)+' %fille%>res'\n",
+"lst(8)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'res'+ascii(39)+') do set siz=%%~zA'\n",
+"lst(9)=':loop'\n",
+"lst(10)='if %siz% equ 0 echo Pattern %1 not found&&goto incr'\n",
+"lst(11)='echo Search results for pattern %1'\n",
+"lst(12)='echo ------------------------------------------------'\n",
+"lst(13)='echo.'\n",
+"lst(14)='type res'\n",
+"lst(15)=':incr'\n",
+"lst(16)='if %i% gtr %b% goto endloop'\n",
+"lst(17)='shift /1'\n",
+"lst(18)='del res'\n",
+"lst(19)='findstr '+ascii(34)+'%1'+ascii(34)+' %fille%>res'\n",
+"lst(20)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'res'+ascii(39)+') do set siz=%%~zA'\n",
+"lst(21)='set /a i+=1'\n",
+"lst(22)='echo.'\n",
+"lst(23)='goto loop'\n",
+"lst(24)=':endloop'\n",
+"lst(25)='pause>NUL'\n",
+"lst(26)='del res'\n",
+" \n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:26\n",
+" mfprintf(v,'%s\n',lst(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.13: Program_14.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 12 : Show the use of set command and the here documenting \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='01|accounts|6213'\n",
+"i=i+1;f(i)='02|admin|5423'\n",
+"i=i+1;f(i)='03|marketing|6521'\n",
+"i=i+1;f(i)='04|personnel|2365'\n",
+"i=i+1;f(i)='05|production|9876'\n",
+"i=i+1;f(i)='06|sales|1006'\n",
+"n=i\n",
+"printf('\n\n$ cat limitlist # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('limitlist','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"halt('')\n",
+"clc\n",
+"i=0\n",
+"i=i+1;f(i)='#! /bin/sh'\n",
+"i=i+1;f(i)='# valcode.sh : Uses a here document to look up for a code list'\n",
+"i=i+1;f(i)='#'\n",
+"i=i+1;f(i)='IFS='+ascii(34)+'|'+ascii(34)+' # Reset field seperator'\n",
+"i=i+1;f(i)='while echo '+ascii(34)+'Enter department code : \c'+ascii(34)+':do'\n",
+"i=i+1;f(i)='read dcode'\n",
+"i=i+1;f(i)='set -- `grep '+ascii(34)+'^$dcode'+ascii(34)+' << limit'\n",
+"i=i+1;f(i)='01|accounts|6213'\n",
+"i=i+1;f(i)='02|admin|5423'\n",
+"i=i+1;f(i)='03|marketing|6521'\n",
+"i=i+1;f(i)='04|personnel|2365'\n",
+"i=i+1;f(i)='05|production|69876'\n",
+"i=i+1;f(i)='06|sales|1006'\n",
+"i=i+1;f(i)='limit`'\n",
+"i=i+1;f(i)=' # Closing ` marks end of standard input'\n",
+"i=i+1;f(i)=' case $# in'\n",
+"i=i+1;f(i)=' 3) echo '+ascii(34)+'Department name : $2\nEmp-id of head of dept : $3\n'+ascii(34)\n",
+"i=i+1;f(i)=' shift 3;; #Flush out the positional parameters'\n",
+"i=i+1;f(i)=' *) echo '+ascii(34)+'Invalid code'+ascii(34)+' ; continue'\n",
+"i=i+1;f(i)='esac'\n",
+"i=i+1;f(i)='done'\n",
+"n=i\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:n\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"i=0\n",
+"i=i+1;f(i)='@echo off'\n",
+"i=i+1;f(i)='echo Executing Validation Programme'\n",
+"i=i+1;f(i)='set Continue?...'\n",
+"i=i+1;f(i)='pause>NUL'\n",
+"i=i+1;f(i)='set chh=y'\n",
+"i=i+1;f(i)=':loop'\n",
+"i=i+1;f(i)='if /I not '+ascii(34)+'%chh%'+ascii(34)+'=='+ascii(34)+'y'+ascii(34)+' goto endloop '\n",
+"i=i+1;f(i)='set /P dcode=Enter department code : '\n",
+"i=i+1;f(i)='del res'\n",
+"i=i+1;f(i)='del lst'\n",
+"i=i+1;f(i)='findstr /B '+ascii(34)+'%dcode%'+ascii(34)+' limitlist.txt>res'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'res'+ascii(39)+') do set siz=%%~zA'\n",
+"i=i+1;f(i)='if %siz% equ 0 echo Invalid code&&set chh=y&&goto loop'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'tokens=2,3 delims=|'+ascii(34)+' %%i in (res) do set dname=%%i&&set id=%%j'\n",
+"i=i+1;f(i)='echo Department name : %dname%'\n",
+"i=i+1;f(i)='echo Emp-id of head of dept : %id%'\n",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='set /P chh=Continue?(y/n) :'\n",
+"i=i+1;f(i)='goto loop'\n",
+"i=i+1;f(i)=':endloop'\n",
+"i=i+1;f(i)='pause>NUL'\n",
+"n=i\n",
+" \n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:n\n",
+" mfprintf(v,'%s\n',f(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('limitlist')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.1: Program_1.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"mode(-1)\n",
+" disp('Example 1: Write a shell script to display the calendar of the present date ,and the shell name')\n",
+" disp('**************************************************************************')\n",
+" disp('Answer : ')\n",
+" disp('')\n",
+" halt('The code related to the example lies in the dependency file shell1.sci ')\n",
+" printf('Today date is %s',date())\n",
+" printf('\nThis month calendar is \n')\n",
+" calendar()\n",
+" t=ans\n",
+" disp(t(1))\n",
+" disp(t(2))\n",
+" disp(t(3))\n",
+" printf('\nMy shell : %s',getshell())\n",
+" disp('**************************************************************************') "
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.2: Program_2.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 2 : Show the method of using read to take two inputs \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='2233|a.k.shukla |g.m. |sales |12/12/52|6000'\n",
+"i=i+1;f(i)='9876|jai sharma |director |production |12/03/50|7000'\n",
+"i=i+1;f(i)='5678|sumit chakrobarty|d.g.m |marketing |19/04/43|6000'\n",
+"i=i+1;f(i)='2356|barun sengupta |director |personnel |11/05/47|7800'\n",
+"i=i+1;f(i)='5423|n.k. gupta |chairman |admin |30/08/56|5400'\n",
+"i=i+1;f(i)='1006|chanchal singhvi |director |sales |03/09/38|6700'\n",
+"i=i+1;f(i)='6213|karuna ganguly |g.m. |accounts |05/06/62|6300'\n",
+"i=i+1;f(i)='1265|s.n. dasgupta |manager |sales |12/09/63|5600'\n",
+"i=i+1;f(i)='4290|jayant Choudhary |executive |production|07/09/50|6000'\n",
+"i=i+1;f(i)='2476|anil aggarwal |manager |sales |01/05/59|5000'\n",
+"i=i+1;f(i)='6521|lalit chowdury |director |marketing |26/09/45|8200'\n",
+"i=i+1;f(i)='3212|shyam saksena |d.g.m |accounts |12/12/55|6000'\n",
+"i=i+1;f(i)='3564|sudhir Agarwal |executive |personnel |06/07/47|7500'\n",
+"i=i+1;f(i)='2345|j.b. saxena |g.m. |marketing |12/03/45|8000'\n",
+"i=i+1;f(i)='0110|v.k. agrawal |g.m. |marketing |31/02/40|9000'\n",
+"n=i\n",
+"printf('\n\n$ cat emp.lst # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('emp.lst','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# emp1.sh : Interactive version - uses read to take two inputs'\n",
+"li(3)='#'\n",
+"li(4)='echo '+ascii(34)+'Enter the pattern to be searched: \c '+ascii(34)+' # No newline'\n",
+"li(5)='read pname' \n",
+"li(6)='echo '+ascii(34)+'Enter the file to be used: \c '+ascii(34)+' #use echo -e or shopt -s xpg_echo in bash'\n",
+"li(7)='read flname'\n",
+"li(8)='echo '+ascii(34)+'Searching for $pname from file $flname '+ascii(34)\n",
+"li(9)='grep '+ascii(34)+'$pname '+ascii(34)+' $flname'\n",
+"li(10)='echo '+ascii(34)+'Selected records shown above '+ascii(34)\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:10\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lst(1)='@echo off'\n",
+"lst(2)='set /P pname=Enter the pattern to be searched: '\n",
+"lst(3)='rem echo.'\n",
+"lst(4)='set /P flname=Enter the file to be used: '\n",
+"lst(5)='rem echo.'\n",
+"lst(6)='echo Searching for %pname% from file %flname%'\n",
+"lst(7)='rem echo.'\n",
+"lst(8)='findstr /C:'+ascii(34)+'%pname%'+ascii(34)+' %flname% '\n",
+"lst(9)='echo Selected records shown above'\n",
+"lst(10)='pause>null'\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:10\n",
+" mfprintf(v,'%s\n',lst(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.3: Program_3.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 3 : Show the method of using command line arguments to take inputs \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='2233|a.k.shukla |g.m. |sales |12/12/52|6000'\n",
+"i=i+1;f(i)='9876|jai sharma |director |production |12/03/50|7000'\n",
+"i=i+1;f(i)='5678|sumit chakrobarty|d.g.m |marketing |19/04/43|6000'\n",
+"i=i+1;f(i)='2356|barun sengupta |director |personnel |11/05/47|7800'\n",
+"i=i+1;f(i)='5423|n.k. gupta |chairman |admin |30/08/56|5400'\n",
+"i=i+1;f(i)='1006|chanchal singhvi |director |sales |03/09/38|6700'\n",
+"i=i+1;f(i)='6213|karuna ganguly |g.m. |accounts |05/06/62|6300'\n",
+"i=i+1;f(i)='1265|s.n. dasgupta |manager |sales |12/09/63|5600'\n",
+"i=i+1;f(i)='4290|jayant Choudhary |executive |production|07/09/50|6000'\n",
+"i=i+1;f(i)='2476|anil aggarwal |manager |sales |01/05/59|5000'\n",
+"i=i+1;f(i)='6521|lalit chowdury |director |marketing |26/09/45|8200'\n",
+"i=i+1;f(i)='3212|shyam saksena |d.g.m |accounts |12/12/55|6000'\n",
+"i=i+1;f(i)='3564|sudhir Agarwal |executive |personnel |06/07/47|7500'\n",
+"i=i+1;f(i)='2345|j.b. saxena |g.m. |marketing |12/03/45|8000'\n",
+"i=i+1;f(i)='0110|v.k. agrawal |g.m. |marketing |31/02/40|9000'\n",
+"n=i\n",
+"printf('\n\n$ cat emp.lst # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('emp.lst','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# emp1.sh : Interactive version - uses read to take two inputs'\n",
+"li(3)='#'\n",
+"li(4)='echo '+ascii(34)+'Program: $0 '+ascii(34)+' #$0 has the program name'\n",
+"li(5)='echo '+ascii(34)+'The number of arguments specified is $# '+ascii(34)\n",
+"li(6)='echo '+ascii(34)+'The arguments are $* '+ascii(34) + ' #All arguments in $*'\n",
+"li(7)='grep '+ascii(34)+'$1'+ascii(34)+'$2'\n",
+"li(8)='echo '+ascii(34)+'\nJob Over '+ascii(34)\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:8\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lst(1)='@echo off'\n",
+"lst(2)='echo Program: '+nam+'.sh'\n",
+"lst(3)='set a=0'\n",
+"lst(4)='for %%x in (%*) do set /A a+=1'\n",
+"lst(5)='echo The number of arguments specified is %a%'\n",
+"lst(6)='echo The arguments are %*'\n",
+"lst(7)='findstr /C:'+ascii(34)+'%1'+ascii(34)+' %2'\n",
+"lst(8)='echo.'\n",
+"lst(9)='echo Job Over'\n",
+"lst(10)='pause>null'\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:10\n",
+" mfprintf(v,'%s\n',lst(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.4: Program_4.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 4 : Show the method of using if else construct in shell progamming \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# emp3.sh : Using if and else'\n",
+"li(3)='#'\n",
+"li(4)='if grep '+ascii(34)+'^$1'+ascii(34)+' /etc/passwd 2> /dev/null # Search username at beginning of line'\n",
+"li(5)='then'\n",
+"li(6)=' echo '+ascii(34)+' Pattern found - Job Over '+ascii(34)\n",
+"li(7)='else'\n",
+"li(8)=' echo '+ascii(34)+' Pattern not found '+ascii(34)\n",
+"li(9)='fi'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:9\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lst(1)='@echo off&&cls'\n",
+"lst(2)='dir /b \Users>passwd'\n",
+"lst(3)='findstr /b '+ascii(34)+'%1'+ascii(34)+' passwd > tmpfil '\n",
+"lst(4)='set a=tmpfil '\n",
+"lst(5)='for /F '+ascii(34)+'usebackq '+ascii(34)+' %%A in ( '+ascii(39)+'%a% '+ascii(39)+') do set y=%%~zA'\n",
+"lst(6)='if %y% neq 0 (echo Pattern Found - Job Over) else (echo Pattern not found )'\n",
+"lst(7)='pause>nul'\n",
+"lst(8)='del tmpfil '\n",
+"lst(9)='del passwd'\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:9\n",
+" mfprintf(v,'%s\n',lst(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.5: Program_5.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 5 : Show the method of using if-elif construct in shell \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='2233|a.k.shukla |g.m. |sales |12/12/52|6000'\n",
+"i=i+1;f(i)='9876|jai sharma |director |production |12/03/50|7000'\n",
+"i=i+1;f(i)='5678|sumit chakrobarty|d.g.m |marketing |19/04/43|6000'\n",
+"i=i+1;f(i)='2356|barun sengupta |director |personnel |11/05/47|7800'\n",
+"i=i+1;f(i)='5423|n.k. gupta |chairman |admin |30/08/56|5400'\n",
+"i=i+1;f(i)='1006|chanchal singhvi |director |sales |03/09/38|6700'\n",
+"i=i+1;f(i)='6213|karuna ganguly |g.m. |accounts |05/06/62|6300'\n",
+"i=i+1;f(i)='1265|s.n. dasgupta |manager |sales |12/09/63|5600'\n",
+"i=i+1;f(i)='4290|jayant Choudhary |executive |production|07/09/50|6000'\n",
+"i=i+1;f(i)='2476|anil aggarwal |manager |sales |01/05/59|5000'\n",
+"i=i+1;f(i)='6521|lalit chowdury |director |marketing |26/09/45|8200'\n",
+"i=i+1;f(i)='3212|shyam saksena |d.g.m |accounts |12/12/55|6000'\n",
+"i=i+1;f(i)='3564|sudhir Agarwal |executive |personnel |06/07/47|7500'\n",
+"i=i+1;f(i)='2345|j.b. saxena |g.m. |marketing |12/03/45|8000'\n",
+"i=i+1;f(i)='0110|v.k. agrawal |g.m. |marketing |31/02/40|9000'\n",
+"n=i\n",
+"printf('\n\n$ cat emp.lst # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('emp.lst','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# emp3a.sh : Using test , $0 and $# in an if-elif-if construct'\n",
+"li(3)='#'\n",
+"li(4)='if test $# -eq 0 ; then'\n",
+"li(5)=' echo '+ascii(34)+'Usage: $0 pattern file'+ascii(34)+' >/dev/tty'\n",
+"li(6)='elif test $# -eq 2 : then'\n",
+"li(7)=' grep '+ascii(34)+'$1'+ascii(34)+' $2 || echo '+ascii(34)+'$1 not found in $2'+ascii(34)+' > /dev/tty'\n",
+"li(8)='else'\n",
+"li(9)=' echo '+ascii(34)+'You did not enter two arguments'+ascii(34)+' >/dev/tty'\n",
+"li(10)='fi'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:10\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lss(1)='@echo off'\n",
+"lss(2)='set x=0'\n",
+"lss(3)='for %%d in (%*) do set /a x+=1'\n",
+"lss(4)='if %x% equ 0 echo Usage nam pattern file&&goto endd'\n",
+"lss(5)='if %x% equ 2 goto process'\n",
+"lss(6)='if %x% neq 2 echo You didn'+ascii(39)+'t enter two arguments&&goto endd'\n",
+"lss(7)=':process'\n",
+"lss(8)='findstr '+ascii(34)+'%1'+ascii(34)+' %2>result1'\n",
+"lss(9)='set b='+ascii(34)+'result1'+ascii(34)\n",
+"lss(10)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'%b%'+ascii(39)+') do set si=%%~zA'\n",
+"lss(11)='if %si% equ 0 echo %1 not found in %2&&goto endd'\n",
+"lss(12)='type result1'\n",
+"lss(13)=':endd'\n",
+"lss(14)='echo.'\n",
+"lss(15)='pause>null'\n",
+"lss(16)='if exist result1 del result1'\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:16\n",
+" mfprintf(v,'%s\n',lss(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.6: Program_6.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 6 : Checks user inputs for null values and runs accordingly \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='2233|a.k.shukla |g.m. |sales |12/12/52|6000'\n",
+"i=i+1;f(i)='9876|jai sharma |director |production |12/03/50|7000'\n",
+"i=i+1;f(i)='5678|sumit chakrobarty|d.g.m |marketing |19/04/43|6000'\n",
+"i=i+1;f(i)='2356|barun sengupta |director |personnel |11/05/47|7800'\n",
+"i=i+1;f(i)='5423|n.k. gupta |chairman |admin |30/08/56|5400'\n",
+"i=i+1;f(i)='1006|chanchal singhvi |director |sales |03/09/38|6700'\n",
+"i=i+1;f(i)='6213|karuna ganguly |g.m. |accounts |05/06/62|6300'\n",
+"i=i+1;f(i)='1265|s.n. dasgupta |manager |sales |12/09/63|5600'\n",
+"i=i+1;f(i)='4290|jayant Choudhary |executive |production|07/09/50|6000'\n",
+"i=i+1;f(i)='2476|anil aggarwal |manager |sales |01/05/59|5000'\n",
+"i=i+1;f(i)='6521|lalit chowdury |director |marketing |26/09/45|8200'\n",
+"i=i+1;f(i)='3212|shyam saksena |d.g.m |accounts |12/12/55|6000'\n",
+"i=i+1;f(i)='3564|sudhir Agarwal |executive |personnel |06/07/47|7500'\n",
+"i=i+1;f(i)='2345|j.b. saxena |g.m. |marketing |12/03/45|8000'\n",
+"i=i+1;f(i)='0110|v.k. agrawal |g.m. |marketing |31/02/40|9000'\n",
+"n=i\n",
+"printf('\n\n$ cat emp.lst # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('emp.lst','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# emp4.sh : Checks user input for null values.Finally runs emp3a.sh'\n",
+"li(3)='#'\n",
+"li(4)='if [ $# -eq 0 ]; then'\n",
+"li(5)=' echo '+ascii(34)+'Enter the string to be searched : \c'+ascii(34)\n",
+"li(6)=' read pname'\n",
+"li(7)=' if [ -z '+ascii(34)+'$pname'+ascii(34)+' ] ; then'\n",
+"li(8)='echo '+ascii(34)+'You have not entered the string '+ascii(34)+' ; exit 1'\n",
+"li(9)='fi'\n",
+"li(10)='echo '+ascii(34)+' Enter the filename to be used : \c '+ascii(34)\n",
+"li(11)='read flname'\n",
+"li(12)='if [ ! -n '+ascii(34)+'$flname'+ascii(34)+'] ; then #!-n same as -z'\n",
+"li(13)='echo '+ascii(34)+'You have not entered the filename '+ascii(34)+' ; exit 2'\n",
+"li(14)='fi'\n",
+"li(15)='emp3a.sh '+ascii(34)+'$pname'+ascii(34)+' '+ascii(34)+'$flname'+ascii(34)'+ascii(34)+' # Runs script to do the job'\n",
+"li(16)='elif test $# -eq 2 : then'\n",
+"li(17)='else'\n",
+"li(18)='emp3a.sh $*'\n",
+"li(19)='fi'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:19\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lss(1)='@echo off'\n",
+"lss(2)='set x=0'\n",
+"lss(3)='for %%d in (%*) do set /a x+=1'\n",
+"lss(4)='if %x% equ 0 echo Usage nam pattern file&&goto endd'\n",
+"lss(5)='if %x% equ 2 goto process'\n",
+"lss(6)='if %x% neq 2 echo You didn'+ascii(39)+'t enter two arguments&&goto endd'\n",
+"lss(7)=':process'\n",
+"lss(8)='findstr '+ascii(34)+'%1'+ascii(34)+' %2>result1'\n",
+"lss(9)='set b='+ascii(34)+'result1'+ascii(34)\n",
+"lss(10)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'%b%'+ascii(39)+') do set si=%%~zA'\n",
+"lss(11)='if %si% equ 0 echo %1 not found in %2&&goto endd'\n",
+"lss(12)='type result1'\n",
+"lss(13)=':endd'\n",
+"lss(14)='echo.'\n",
+"lss(15)='pause>null'\n",
+"lss(16)='if exist result1 del result1'\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen('emp3a.sh.bat','wt')\n",
+"for i=1:16\n",
+" mfprintf(v,'%s\n',lss(i))\n",
+"end\n",
+"mclose(v)\n",
+"lss(1)='@echo off'\n",
+"lss(2)='cls'\n",
+"lss(3)='set argct=0'\n",
+"lss(4)='for %%x in (%*) do set /a argct+=1'\n",
+"lss(5)='if %argct% equ 0 goto intake'\n",
+"lss(6)='emp3a.sh %*'\n",
+"lss(7)='goto endx'\n",
+"lss(8)=':intake'\n",
+"lss(9)='set /p pname=Enter the string to be searched:' \n",
+"lss(10)='if '+ascii(34)+'%pname%'+ascii(34)+'=='+ascii(34)+''+ascii(34)+' echo You have not entered the string&&goto endx'\n",
+"lss(11)='set /p flname=Enter the filename to be used: '\n",
+"lss(12)='if '+ascii(34)+'%flname%'+ascii(34)+'=='+ascii(34)+''+ascii(34)+' echo You have not entered the filename&&goto endx'\n",
+"lss(13)='emp3a.sh %pname% %flname%'\n",
+"lss(14)=':endx'\n",
+"lss(15)='pause>null'\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:15\n",
+" mfprintf(v,'%s\n',lss(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')\n",
+"mdelete('emp3a.sh.bat')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.7: Program_7.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 7 : Show the method of determining the attributes of a file in unix \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"i=0\n",
+"i=i+1;f(i)='2233|a.k.shukla |g.m. |sales |12/12/52|6000'\n",
+"i=i+1;f(i)='9876|jai sharma |director |production |12/03/50|7000'\n",
+"i=i+1;f(i)='5678|sumit chakrobarty|d.g.m |marketing |19/04/43|6000'\n",
+"i=i+1;f(i)='2356|barun sengupta |director |personnel |11/05/47|7800'\n",
+"i=i+1;f(i)='5423|n.k. gupta |chairman |admin |30/08/56|5400'\n",
+"i=i+1;f(i)='1006|chanchal singhvi |director |sales |03/09/38|6700'\n",
+"i=i+1;f(i)='6213|karuna ganguly |g.m. |accounts |05/06/62|6300'\n",
+"i=i+1;f(i)='1265|s.n. dasgupta |manager |sales |12/09/63|5600'\n",
+"i=i+1;f(i)='4290|jayant Choudhary |executive |production|07/09/50|6000'\n",
+"i=i+1;f(i)='2476|anil aggarwal |manager |sales |01/05/59|5000'\n",
+"i=i+1;f(i)='6521|lalit chowdury |director |marketing |26/09/45|8200'\n",
+"i=i+1;f(i)='3212|shyam saksena |d.g.m |accounts |12/12/55|6000'\n",
+"i=i+1;f(i)='3564|sudhir Agarwal |executive |personnel |06/07/47|7500'\n",
+"i=i+1;f(i)='2345|j.b. saxena |g.m. |marketing |12/03/45|8000'\n",
+"i=i+1;f(i)='0110|v.k. agrawal |g.m. |marketing |31/02/40|9000'\n",
+"n=i\n",
+"printf('\n\n$ cat emp.lst # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('emp.lst','wt')\n",
+"for i=1:n\n",
+" mfprintf(u,'%s\n',f(i))\n",
+" printf('%s\n',f(i))\n",
+"end\n",
+"mclose(u)\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# filetest.sh : Tests file attributes'\n",
+"li(3)='#'\n",
+"li(4)='if [ ! -e $1 ]; then'\n",
+"li(5)='echo '+ascii(34)+'File does not exist'+ascii(34)\n",
+"li(6)='elif [! -r $1]; then '\n",
+"li(7)='echo '+ascii(34)+'File is not readable'+ascii(34)\n",
+"li(8)='elif [! -w $1]; then'\n",
+"li(9)='echo '+ascii(34)+'File is not writable'+ascii(34)\n",
+"li(10)='else'\n",
+"li(11)=' echo '+ascii(34)+'File is both readable and writable'+ascii(34)\n",
+"li(12)=' fi'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:12\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lss(1)='@echo off'\n",
+"lss(2)='if not exist %1 echo file does not exist&&goto ends'\n",
+"lss(3)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%A in ('+ascii(39)+'%1'+ascii(39)+') do set attr=%%~aA&&set '+ascii(34)+'wrtatt=%attr:~1,1%'+ascii(34)+''\n",
+"lss(4)='if '+ascii(34)+'%wrtatt%'+ascii(34)+'=='+ascii(34)+'-'+ascii(34)+' (goto rdwt) else goto rdnwt'\n",
+"lss(6)=':rdwt '\n",
+"lss(7)='echo File is both readable and writable&&goto ends'\n",
+"lss(8)=':rdnwt '\n",
+"lss(9)='echo File is not writable'\n",
+"lss(10)=':ends'\n",
+"lss(11)='pause>nul'\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:11\n",
+" mfprintf(v,'%s\n',lss(i))\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open another terminal,then go to the directory %s and then execute using the following instruction\n\n$ shell %s.sh \n\nThank You \n\n',curr,nam)\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\nPLEASE EXECUTE THE SCRIPT IN THE COMMAND PROMPT TWICE IF YOU DO NOT GET THE OUTPUT IN THE \n FIRST ATTEMPT.THERE IF SOME TECHNICAL ERROR\nSORRY FOR THE INCONVENIENCE CAUSED')\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.8: Program_8.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"\n",
+"printf('Example 8 : Show the method of using if else construct in shell progamming \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='#menu.sh:Uses case to offer 5-item menu'\n",
+"li(3)='#'\n",
+"li(4)='echo '+ascii(34)+' MENU\n1.List of files\n2.Processes of user\n3. Todays date'\n",
+"li(5)='4.Users of system\n5. Quit the shell\nEnter your option: \c'+ascii(34)+''\n",
+"li(6)='read choice'\n",
+"li(7)='case '+ascii(34)+'$choice'+ascii(34)+' in'\n",
+"li(8)=' 1) ls -l ;;'\n",
+"li(9)=' 2) ps -f ;;'\n",
+"li(10)=' 3)date ;;'\n",
+"li(11)=' 4)who ;;'\n",
+"li(12)=' 5)exit ;;'\n",
+"li(13)=' *) echo '+ascii(34)+'Invalid Option'+ascii(34)+' # ;; not really required for the last option'\n",
+"li(14)=' end'\n",
+"li(15)=' esac'\n",
+"\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"\n",
+"for i=1:15\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"\n",
+"lss(1)='@echo off'\n",
+"lss(2)='cls'\n",
+"lss(3)='echo.'\n",
+"lss(4)='echo.'\n",
+"lss(5)='echo MENU'\n",
+"lss(6)=':retrn'\n",
+"lss(7)='echo.'\n",
+"lss(8)='echo 1. List of files'\n",
+"lss(9)='echo 2. Processes of user'\n",
+"lss(10)='echo 3. Today'+ascii(34)+'s date'\n",
+"lss(11)='echo 4. Users of system'\n",
+"lss(12)='echo 5. Quit to UNIX'\n",
+"lss(13)='choice /c 123456 /d 6 /t 20 /n /m '+ascii(34)+'Enter your option'+ascii(34)+''\n",
+"lss(14)='if ERRORLEVEL 6 pause>NUL&&echo Invalid option&&goto retrn'\n",
+"lss(15)='if ERRORLEVEL 5 pause>NUL&&exit'\n",
+"lss(16)='if ERRORLEVEL 4 pause>NUL&&net user&&goto ends'\n",
+"lss(17)='if ERRORLEVEL 3 pause>NUL&&powershell date&&goto ends'\n",
+"lss(18)='if ERRORLEVEL 2 pause>NUL&&tasklist&&goto ends'\n",
+"lss(19)='if ERRORLEVEL 1 pause>NUL&&dir&&goto ends'\n",
+"lss(20)=':ends'\n",
+"lss(21)='pause>NUL'\n",
+"\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"\n",
+"\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:21\n",
+" mfprintf(v,'%s\n',lss(i))\n",
+"end\n",
+"mclose(v)\n",
+"\n",
+"\n",
+"\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"\n",
+"mdelete(nam+'.sh.bat')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 14.9: Program_9.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 9 : Show the use of while loop \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\n1. Here all instructions are preloaded in the form of a demo\n\nInitially the whole perl script is displaying and then \n the result of the same can be seen in the command line interpreter.\n\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. PRESS ENTER AFTER EACH COMMAND to see its RESULT\n\n5. PRESS ENTER AFTER EACH RESULT TO GO TO THE NEXT COMMAND\n')\n",
+"halt('.............Press [ENTER] to continue.....')\n",
+"halt('')\n",
+"clc\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"halt('')\n",
+"clc\n",
+"li(1)='#!/bin/sh'\n",
+"li(2)='# emp5.sh: Shows use of the while loop'\n",
+"li(3)='#'\n",
+"li(4)='answer=y'\n",
+"li(5)='while [ '+ascii(34)+'$answer'+ascii(34)+' = '+ascii(34)+'y'+ascii(34)+' ] # The control command'\n",
+"li(6)='do'\n",
+"li(7)='echo '+ascii(34)+'Enter the code and description: \c'+ascii(34)+'>/dev/tty'\n",
+"li(8)='read code description # Read both together'\n",
+"li(9)='echo '+ascii(34)+'$code|$description'+ascii(34)+'>>newlist # Append a line to newlist'\n",
+"li(10)='echo '+ascii(34)+'Enter any more(y/n)? \c'+ascii(34)+'>/dev/tty'\n",
+"li(11)='read anymore'\n",
+"li(12)='case $anymore in'\n",
+"li(13)=' y*|Y*) answer=y ;; # also accepts yes,YES etc'\n",
+"li(14)=' n*|N*) answer=n ;; # also accepts no,NO elc'\n",
+"li(15)=' *) answer=y ;;'\n",
+"li(16)='esac'\n",
+"li(17)='done'\n",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"for i=1:17\n",
+" printf('%s\n',li(i))\n",
+"end\n",
+"halt(' ')\n",
+"clc\n",
+"lst(1)='@echo off&&cls'\n",
+"lst(2)='set answer=y'\n",
+"lst(3)=':loop'\n",
+"lst(4)='if not '+ascii(34)+'%answer%'+ascii(34)+'=='+ascii(34)+'y'+ascii(34)+' goto endloop'\n",
+"lst(5)='set /p varr=Enter the code and the description: '\n",
+"lst(6)='for /F '+ascii(34)+'tokens=1,2* '+ascii(34)+' %%i in ( '+ascii(34)+'%varr%'+ascii(34)+') do set code=%%i&&set description=%%j '\n",
+"lst(7)='echo %code%:%description%>>newlist'\n",
+"lst(8)='set /p anymore=Enter any more (y/n)? '\n",
+"lst(9)='if '+ascii(34)+'%anymore%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' set answer=n&&goto loop'\n",
+"lst(10)='if '+ascii(34)+'%anymore%'+ascii(34)+'=='+ascii(34)+'no'+ascii(34)+' set answer=n&&goto loop'\n",
+"lst(11)='if '+ascii(34)+'%anymore%'+ascii(34)+'=='+ascii(34)+'No'+ascii(34)+' set answer=n&&goto loop'\n",
+"lst(12)='if '+ascii(34)+'%anymore%'+ascii(34)+'=='+ascii(34)+'NO'+ascii(34)+' set answer=n&&goto loop'\n",
+"lst(13)='if '+ascii(34)+'%anymore%'+ascii(34)+'=='+ascii(34)+'N'+ascii(34)+' set answer=n&&goto loop'\n",
+"lst(14)='set answer=y'\n",
+"lst(15)='goto loop'\n",
+"lst(16)=':endloop'\n",
+"lst(17)='pause>NUL'\n",
+"lst(18)='echo.&&cls'\n",
+"lst(19)='echo Do you want to see the file newlist'\n",
+"lst(20)='set /p chh=Enter y for Yes and n for No: '\n",
+"lst(21)='if '+ascii(34)+'%chh%'+ascii(34)+'=='+ascii(34)+'y'+ascii(34)+' type newlist'\n",
+"lst(22)='pause>NUL&&echo Thank you&&del newlist'\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.sh.bat','wt')\n",
+"for i=1:22\n",
+" mfprintf(v,'%s\n',lst(i))\n",
+"end\n",
+"mclose(v)\n",
+"printf('\n# type the following command in the command line interpreter as soon as it appears')\n",
+"printf(' \n %c %s.sh %c [COMMANDLINE ARGUMENTS][ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.sh [COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing ShellScript in Command Line Prompt<-------------- ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)\n",
+"mdelete(nam+'.sh.bat')"
+ ]
+ }
+],
+"metadata": {
+ "kernelspec": {
+ "display_name": "Scilab",
+ "language": "scilab",
+ "name": "scilab"
+ },
+ "language_info": {
+ "file_extension": ".sce",
+ "help_links": [
+ {
+ "text": "MetaKernel Magics",
+ "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
+ }
+ ],
+ "mimetype": "text/x-octave",
+ "name": "scilab",
+ "version": "0.7.1"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}