summaryrefslogtreecommitdiff
path: root/Unix_Concepts_And_Applications_by_S_Das
diff options
context:
space:
mode:
Diffstat (limited to 'Unix_Concepts_And_Applications_by_S_Das')
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/1-Getting_Started.ipynb350
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/14-Essential_Shell_Programming.ipynb1434
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/18-awk_An_Advanced_Filter.ipynb283
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/19-perl_The_Master_Manipulator.ipynb1594
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/2-The_Unix_Architecture_and_Command_Usage.ipynb248
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/21-Advanced_Shell_Programming.ipynb564
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/23-Systems_Programming_1_Files.ipynb1245
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/24-Systems_Programming_2_Process_Control.ipynb1509
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/3-General_Purpose_Utilities.ipynb380
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/4-The_File_System.ipynb389
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/5-Handling_Ordinary_Files.ipynb793
-rw-r--r--Unix_Concepts_And_Applications_by_S_Das/7-Basic_File_Attributes.ipynb32
12 files changed, 8821 insertions, 0 deletions
diff --git a/Unix_Concepts_And_Applications_by_S_Das/1-Getting_Started.ipynb b/Unix_Concepts_And_Applications_by_S_Das/1-Getting_Started.ipynb
new file mode 100644
index 0000000..c58aa4f
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/1-Getting_Started.ipynb
@@ -0,0 +1,350 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 1: Getting Started"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.1: Date_and_Time.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear()\n",
+"dt=getdate()\n",
+"//clc()\n",
+"disp('Example 1 : Write a code sequence to display the current date and time')\n",
+"printf('\n**********************************************************\n')\n",
+"disp('Answer : ')\n",
+"printf('\n')\n",
+"printf('The current date is %s and the current time is %d : %d : %d \nThe day is ',date(),dt(7),dt(8),dt(9))\n",
+"select dt(5) \n",
+" case 1 then\n",
+" printf('Sunday')\n",
+" case 2 then\n",
+" printf('Monday')\n",
+" case 3 then\n",
+" printf('Tuesday')\n",
+" case 4 then\n",
+" printf('Wednesday')\n",
+" case 5 then\n",
+" printf('Thursday')\n",
+" case 6 then\n",
+" printf('Friday')\n",
+" case 7 then\n",
+" printf('Saturday')\n",
+"end\n",
+"printf('.')\n",
+"printf('\n**********************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.2: Clearing_the_Screen.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear()\n",
+"//clc()\n",
+"disp('Example 2 : Clear the current session window at the press of a key')\n",
+"printf('\n**********************************************************\n')\n",
+"disp('Answer :')\n",
+"disp('')\n",
+"disp('Press any key to clear the Session window ')\n",
+"halt('')\n",
+"//clc()"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.3: Calendar_display.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear()\n",
+"//clc()\n",
+"printf('Example 3 : Display the calendar of the current month and of a date \nentered by the user ')\n",
+"printf('\n**********************************************************\n')\n",
+"printf('Answer :\n\n\n')\n",
+"printf('The current date is %s whose calendar is ',date())\n",
+"ct=calendar()\n",
+"clc(19)\n",
+"disp(ct(1))\n",
+"disp(ct(2))\n",
+"disp(ct(3))\n",
+"printf('\n--------------------------------------------------------------------------------------\n')\n",
+"printf('Enter a date whose calendar is to be displayed \n')\n",
+"x=input('Enter in the format [dd,mm,yyyy],ALONG WITH THE PARENTHESIS ')\n",
+"ct=calendar(x(3),x(2))\n",
+"clc(21)\n",
+"disp(ct(1))\n",
+"disp(ct(2))\n",
+"disp(ct(3))\n",
+"printf('\n\nEntered Date is %d - %d - %d \n',x(1),x(2),x(3))\n",
+"printf('\n***********************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.4: Users_present.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"disp('Example 4 : Display all the current users in the Current Unix Session')\n",
+"disp('')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer :')\n",
+"printf('THE FOLLOWING LINES OF CODE RUN \nONLY IN SCILAB INSTALLED IN UNIX ENVIRONMENT.....')\n",
+"printf('\nTHE CONSOLE GETS EXITED IN OTHER\n OPERATING SYSTEMS')\n",
+"if(getos() ~= 'Linux' )then\n",
+" disp('')\n",
+" halt('Press any key to end the script since the OS is not Linux')\n",
+" printf('Close the Scilab Console?....\ny :Yes\nAny other key:No')\n",
+" st = input('','s')\n",
+" clc(1)\n",
+" if( st == 'y') then\n",
+" exit\n",
+" end\n",
+"else\n",
+" unix_w('who')\n",
+"end\n",
+"printf('\n*******************************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.5: Processes.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"disp('Example 5: Display all the current working processes in the current session')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer : ')\n",
+"disp('')\n",
+"halt('Press Enter to display the processes')\n",
+"if (getos()=='Windows') then\n",
+"clc(1)\n",
+"powershell('ps')\n",
+"else\n",
+" clc(1)\n",
+" unix_w('ps')\n",
+"end\n",
+"printf('\n*******************************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.6: Listing_Files.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"clc\n",
+"\n",
+"disp('Example 6 : Display all the files in the current directory and files beginning with ->Ex<-')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer : ')\n",
+"halt('Press [Enter] to continue')\n",
+"disp('Files in the current directory ')\n",
+"mode(0)\n",
+"ls\n",
+"mode(-1)\n",
+"halt('Press Enter to see files beginning with ->Ex<-')\n",
+"printf('\n-------------------------------------------------------------------------------------------------\n')\n",
+"disp('Files Beginning with ->Ex<-')\n",
+"mode(0)\n",
+"ls Ex*\n",
+"mode(-1)\n",
+"printf('\n*******************************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.7: Number_of_files_Unix_only.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"\n",
+"clear\n",
+"clc\n",
+"disp('Example 6 : Display the number of files in the current directory ')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer :')\n",
+"printf('THE FOLLOWING LINES OF CODE RUN \nONLY IN SCILAB INSTALLED IN UNIX ENVIRONMENT.....')\n",
+"printf('\nTHE CONSOLE GETS EXITED IN OTHER\n OPERATING SYSTEMS')\n",
+"if(getos() ~= 'Linux' )then\n",
+" disp('')\n",
+" halt('Press any key to end the script since the OS is not Linux')\n",
+" printf('Close the Scilab Console?....\ny :Yes\nAny other key:No')\n",
+" st = input('','s')\n",
+" clc(1)\n",
+" if( st == 'y') then\n",
+" exit\n",
+" end\n",
+"else\n",
+" unix_w('ls|wc')\n",
+"end\n",
+"printf('\n*******************************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.8: Programming_basics.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"disp('Example 8: Write a code-sequence to find show primitive programming ')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer : ')\n",
+"disp('The following programme takes an input from the user adds 2 to it and displays the result')\n",
+"disp('')\n",
+"halt('Ready???...Press Enter to continue')\n",
+"a=input('Enter any number : ')\n",
+"clc(1)\n",
+"printf('\n\nThe new result is %d',a+2)\n",
+"printf('\n*******************************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 1.9: Exitting.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"disp('Example 9: Write a code-sequence to exit the console')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer : ')\n",
+"halt('Ready???...Press Enter to continue')\n",
+" printf('Close the Scilab Console?....\ny :Yes\nAny other key:No')\n",
+" st = input('','s')\n",
+" clc(1)\n",
+" if( st == 'y') then\n",
+" exit\n",
+" end\n",
+"printf('\n*******************************************************************\n')"
+ ]
+ }
+],
+"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
+}
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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/18-awk_An_Advanced_Filter.ipynb b/Unix_Concepts_And_Applications_by_S_Das/18-awk_An_Advanced_Filter.ipynb
new file mode 100644
index 0000000..fccb5e3
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/18-awk_An_Advanced_Filter.ipynb
@@ -0,0 +1,283 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 18: awk An Advanced Filter"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.1: Program_1.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 1 : Show the method of using field extraction in awk \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('empn.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",
+"i=0\n",
+"i=i+1;f(i)='BEGIN {IFS='+ascii(34)+'|'+ascii(34)\n",
+"i=i+1;f(i)='printf '+ascii(34)+'\t\tEmployee abstract\n\n'+ascii(34)\n",
+"i=i+1;f(i)='} $6 > 7500 { # Increemnt the variables for serial number and pay'\n",
+"i=i+1;f(i)=' kount++ ; tot+= $6 # Multiple assignments in one line'\n",
+"i=i+1;f(i)=' printf '+ascii(34)+'%3d % -20s % -12s %d\n'+ascii(34)+',kount,$2,$3,$6'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)='END {'\n",
+"i=i+1;f(i)=' printf '+ascii(34)+'\n\tThe averge basic pay is %6d\n'+ascii(34)+',tot/kount'\n",
+"i=i+1;f(i)='}'\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)='cls'\n",
+"i=i+1;f(i)='echo Employee abstract'\n",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='set t=0'\n",
+"i=i+1;f(i)='set tot=0'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'tokens=2,3,6 delims=|'+ascii(34)+' %%i in (%1) do if %%k gtr 7500 set /a t+=1&&echo %%i %%j %%k>>res&&set /a tot+=%%k' \n",
+"i=i+1;f(i)='type res'\n",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='set /a tot/=i'\n",
+"i=i+1;f(i)='echo The average basic pay is %tot%'\n",
+"i=i+1;f(i)='del res'\n",
+"n=i\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute using the instructions\n\nThank You \n\n')\n",
+" halt(' ')\n",
+" exit\n",
+"end\n",
+"v=mopen(nam+'.awk.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.awk empn.lst %c [ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.awk empn.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing awkScript 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+'.awk.bat')\n",
+"mdelete('empn.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 18.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 field extraction and begin-end in awk \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('empn.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",
+"i=0\n",
+"i=i+1;f(i)='begin {'\n",
+"i=i+1;f(i)='fs = '+ascii(34)+'|'+ascii(34)+''\n",
+"i=i+1;f(i)='printf '+ascii(34)+'%46s\n'+ascii(34)+', '+ascii(34)+'Basic Da Hra Gross'+ascii(34)+''\n",
+"i=i+1;f(i)='}/sales|marketing/ {'\n",
+"i=i+1;f(i)=' # Calculate the da, hra and gross pay'\n",
+"i=i+1;f(i)=' da = 0.25*$6 ; hra = 0.50*$6 ; gp = $6+hra+da'\n",
+" \n",
+"i=i+1;f(i)=' # Store the aggregates in seperate arrays'\n",
+"i=i+1;f(i)=' tot[1] += $6 ; tot[6] += da ; tot[3] += hra ; tot[4] += gp'\n",
+"i=i+1;f(i)=' kount++'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)='END { # Print the averages'\n",
+"i=i+1;f(i)=' printf '+ascii(34)+'\t Average %5d %5d %5d %5d\n'+ascii(34)+' , \'\n",
+"i=i+1;f(i)=' tot[1]/kount, tot[2]/kount, tot[3]/kount, tot[4]/kount'\n",
+"i=i+1;f(i)='}'\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)='cls'\n",
+"i=i+1;f(i)='if exist temp.lst del temp.lst'\n",
+"i=i+1;f(i)='if exist cntl del cntl'\n",
+"i=i+1;f(i)='findstr /N /R '+ascii(34)+'^'+ascii(34)+' %1>temp.lst'\n",
+"i=i+1;f(i)='findstr /N /R '+ascii(34)+'^'+ascii(34)+' %1|find /C '+ascii(34)+':'+ascii(34)+'>cntl'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'delims= '+ascii(34)+' %%i in (cntl) do set max=%%i'\n",
+"i=i+1;f(i)='del cntl'\n",
+"i=i+1;f(i)='set kount=1'\n",
+"i=i+1;f(i)='if exist lin del lin'\n",
+"i=i+1;f(i)='set tot1=0'\n",
+"i=i+1;f(i)='set tot2=0'\n",
+"i=i+1;f(i)='set tot3=0'\n",
+"i=i+1;f(i)='set tot4=0'\n",
+"i=i+1;f(i)=':loop'\n",
+"i=i+1;f(i)='if %kount% gtr %max% goto endloop'\n",
+"i=i+1;f(i)='findstr /B '+ascii(34)+'%kount%'+ascii(34)+' temp.lst>lin'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'tokens=6 delims=|'+ascii(34)+' %%i in (lin) do set basic=%%i'\n",
+"i=i+1;f(i)='set /a da=basic/4'\n",
+"i=i+1;f(i)='set /a hra=basic/2'\n",
+"i=i+1;f(i)='set /a gp=basic+da+hra'\n",
+"i=i+1;f(i)='set /a tot1+=basic&&set /a tot2+=da&&set /a tot3+=hra&&set /a tot4+=gp'\n",
+"i=i+1;f(i)='set /a kount+=1'\n",
+"i=i+1;f(i)='goto loop'\n",
+"i=i+1;f(i)=':endloop'\n",
+"i=i+1;f(i)='set /a '+ascii(39)+'tot1/=kount,tot2/=kount,tot3/=kount,tot4/=kount'+ascii(39)+''\n",
+"i=i+1;f(i)='echo Average %tot1% %tot2% %tot3% %tot4%'\n",
+"i=i+1;f(i)='pause>NUL'\n",
+"n=i\n",
+"v=mopen(nam+'.awk.bat','wt')\n",
+"for i=1:n\n",
+" mfprintf(v,'%s\n',f(i))\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute using the instructions\n\nThank You \n\n')\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.awk empn.lst %c [ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.awk empn.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing awkScript 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+'.awk.bat')\n",
+"mdelete('empn.lst')"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/19-perl_The_Master_Manipulator.ipynb b/Unix_Concepts_And_Applications_by_S_Das/19-perl_The_Master_Manipulator.ipynb
new file mode 100644
index 0000000..5910d70
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/19-perl_The_Master_Manipulator.ipynb
@@ -0,0 +1,1594 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 19: perl The Master Manipulator"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.10: Program_10.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 10 : Show the method of converting a decimal to binary in perl \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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Converts decimal numbers to binary '\n",
+"li(3)='#'\n",
+"li(4)='die('+ascii(34)+'You have not entered any number\n'+ascii(34)+') if (@ARGV == 0 ) ;'\n",
+"li(5)='foreach $number (@ARGV) { '\n",
+"li(6)=' $original_number = $number ;'\n",
+"li(7)=' until ($number == 0) {'\n",
+"li(8)=' $bit = $number % 2 ; # Find the remainder bit'\n",
+"li(9)=' unshift (@bit_arr , $bit ) ; # Insert bit at beginning'\n",
+"li(10)=' $number = int($number / 2) ; '\n",
+"li(11)=' }'\n",
+"li(12)=' $binary_number = join ( '+ascii(34)+ascii(34)+', @bit_arr) ; # Join or nothing!' \n",
+"li(13)=' print('+ascii(34)+'The binary number of $original_number is $binary_number\n'+ascii(34)+') ;'\n",
+"li(14)=' $#bit_arr = -1 ; } #deletes all array elements'\n",
+"li(15)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:14\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=14 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl [THE NUMBERS AS COMMANDLINE ARGUMENTS] %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl [THE NUMBERS AS COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.11: Program_11.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 11 : Show the method of searching in an array using %cgrep%c in perl \n',ascii(39),ascii(39))\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\n6.A file named %cdept.lst%c with the necessary details gets created automatically for the session',ascii(34),ascii(34))\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 dept.lst # to open the file dept.lst')\n",
+"halt(' ')\n",
+"u=mopen('dept.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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Searches array for a string or regular expression '\n",
+"li(3)='#'\n",
+"li(4)='@dept_arr = <> ; # Read file into array'\n",
+"li(5)='for ($i=0 ; $i<3 ; $i++) { # Can use only three times'\n",
+"li(6)=' print('+ascii(34)+'Enter a code to look up: '+ascii(34)+') ; '\n",
+"li(7)=' chop($code = <STDIN>) ;'\n",
+"li(8)=' @found_arr = grep (/^$code/, @dept_arr) ; # Search at beginning'\n",
+"li(9)=' if ($#found_arr == -1 || $code eq '+ascii(34)+ascii(34)+') { # -1 means null array'\n",
+"li(10)=' print('+ascii(34)+'Code does not exist\n'+ascii(34)+') ; '\n",
+"li(11)=' next ; # Go to the beginning of loop'\n",
+"li(12)=' }'\n",
+"li(13)=' @tt=split(/\|/ ,$found_arr[0]) ; # Split first element only '\n",
+"li(14)=' print('+ascii(34)+'Code = $code Description = $tt[1]\n'+ascii(34)+') ; '\n",
+"li(15)=' }'\n",
+"li(16)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"printf('\n$ cat %s.pl #open the perlscript file %s.pl\n\n',nam,nam)\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:16\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=16 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl dept.lst %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl dept.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')\n",
+"mdelete('dept.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.12: Program_12.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 12 : Show the method of using %cASSOCIATIVE ARRAYS%c in perl \n',ascii(39),ascii(39))\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\n4. 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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"printf('\n$ cat %s #to open perlscript file %s \n ',nam,nam)\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Uses an associative array '\n",
+"li(3)='#'\n",
+"li(4)='%region = ('+ascii(34)+'N'+ascii(34)+','+ascii(34)+'North'+ascii(34)+','+ascii(34)+'S'+ascii(34)+','+ascii(34)+'South'+ascii(34)+','+ascii(34)+'E'+ascii(34)+','+ascii(34)+'East'+ascii(34)+','+ascii(34)+'W'+ascii(34)+','+ascii(34)+'West'+ascii(34)+') ;'\n",
+"li(5)='die('+ascii(34)+'Nothing entered in commandline\n'+ascii(34)+') if (@ARGV == 0 ) ;'\n",
+"li(6)='foreach $letter (@ARGV) {'\n",
+"li(7)=' print('+ascii(34)+'The letter $letter stands for $region{$letter}'+ascii(34)+'.'+ascii(34)+'\n'+ascii(34)+') ; '\n",
+"li(8)='}'\n",
+"li(9)='@key_list = keys(%region) ; # List of subscripts'\n",
+"li(10)='print('+ascii(34)+'The subscripts are @key_list\n'+ascii(34)+') ; '\n",
+"li(11)='@value_list = values %region ; # List of values'\n",
+"li(12)='print('+ascii(34)+'The values are @value_list\n'+ascii(34)+') ; '\n",
+"li(13)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:13\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=13 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.13: Program_13.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 13 : Show the method of finding the frequency of occurence in perl \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\n6.Afile named %cemp.lst%c with the necessary details gets created automatically for the session',ascii(34),ascii(34))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Counts frequency of occurence of an item '\n",
+"li(3)='#'\n",
+"li(4)='while (<>) {'\n",
+"li(5)=' @t=split(/\|/) ; # | has to be escaped'\n",
+"li(6)=' $dept= $t[3] ; # Department is fourth field'\n",
+"li(7)=' $deptlist{$dept}++ ; # same as ++'\n",
+"li(8)=' }'\n",
+"li(9)='foreach $det (sort (keys %deptlist)) {'\n",
+"li(10)=' print('+ascii(34)+'$det: $deptlist{$det}\n'+ascii(34)+') ; '\n",
+"li(11)=' }'\n",
+"li(12)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"printf('\n $ cat %s # to open the perlscript file %s ',nam,nam)\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:12\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=12 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl emp.lst %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl emp.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.14: Program_14.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 14 : Show the method of using regular expressions in perl \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\n6.Afile named %cemp.lst%c with the necessary details gets created automatically for the session',ascii(34),ascii(34))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Uses s and tr functions for substitution '\n",
+"li(3)='#'\n",
+"li(4)='print('+ascii(34)+'Last two digits of date of birth: '+ascii(34)+');'\n",
+"li(5)='$yearin = <STDIN> ;'\n",
+"li(6)='chop($yearin); # Remove \n else comparison will fail later'\n",
+"li(7)=' '\n",
+"li(8)='$found = 0;'\n",
+"li(9)='while (<>) {'\n",
+"li(10)=' @line = split(/\|/) ; '\n",
+"li(11)=' $name = $line[1] ; $emp_id = $line[0] ; '\n",
+"li(12)=' @tt=split(/\//,$line[4]); #Splits date field'\n",
+"li(13)=' $year = $tt[2] ; #2-digit year extracted ..'\n",
+"li(14)=li(7)\n",
+"li(15)=' if($year eq $yearin) { # .. and compared with the user input'\n",
+"li(16)=' $found = 1;'\n",
+"li(17)=' $name =~ tr/a-z/A-Z/ ; # Name field changed to caps'\n",
+"li(18)=' $emp_id =~ s/^/9/ ; # Adds 9 as a prefix to employee id'\n",
+"li(19)=' $line[0] = $emp_id ; #Reassign'\n",
+"li(20)=' $line[1] = $name ; #with changes'\n",
+"li(21)=' $x=join('+ascii(34)+':'+ascii(34)+', @line) ;'\n",
+"li(22)=' $x=~s/\s+:/:/g ; #Removes whitespace before delimiter'\n",
+"li(23)=' $x=~s#/#-#g ; #New delimiter in date'\n",
+"li(24)=' print $x; } }'\n",
+"li(25)='print('+ascii(34)+'Year 19'+ascii(34)+'. $yearin . '+ascii(34)+'not found\n'+ascii(34)+') if $found eq 0 ;'\n",
+"li(26)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:26\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=26 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl emp.lst %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl emp.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.15: Program_15.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"pwd\n",
+"curr=ans\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 15 : Show the method of using TRE and IRE in perl \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\n6.Afile named %cemp.lst%c with the necessary details gets created automatically for the session',ascii(34),ascii(34))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl -n'\n",
+"li(2)='# Script: '+nam+'.pl - Reports a date in format dd-mm-yyyy using a TRE '\n",
+"li(3)='#' \n",
+"li(4)='@month[1..12] = ('+ascii(34)+'Jan'+ascii(34)+','+ascii(34)+'Feb'+ascii(34)+','+ascii(34)+'Mar'+ascii(34)+','+ascii(34)+'Apr'+ascii(34)+','+ascii(34)+'May'+ascii(34)+','+ascii(34)+'Jun'+ascii(34)+','+ascii(34)+'Jul'+ascii(34)+','+ascii(34)+'Aug'+ascii(34)+','+ascii(34)+'Sep'+ascii(34)+','+ascii(34)+'Oct'+ascii(34)+','+ascii(34)+'Nov'+ascii(34)+','+ascii(34)+'Dec'+ascii(34)+') ;'\n",
+"li(5)='@x = split(/\|/) ;'\n",
+"li(6)='$x[4] =~ /(\d+).(\d+).(\d+)/ ; #Splits into $1,$2,and $3'\n",
+"li(7)='$x[4] = join ('+ascii(34)+'-'+ascii(34)+',$1,$month[$2],'+ascii(34)+'19$3'+ascii(34)+');'\n",
+"li(8)='$t = (join'+ascii(34)+':'+ascii(34)+', @x);'\n",
+"li(9)='print $t ;'\n",
+"li(10)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:9\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=10 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl emp.lst %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl emp.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.16: Program_16.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 16 : Show the method of lowlevel filehandling in perl \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\n6.Afile named %cemp.lst%c with the necessary details gets created automatically for the session',ascii(34),ascii(34))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl '\n",
+"li(2)='# Script: '+nam+'.pl - Shows use of low-level filehandling available in perl '\n",
+"li(3)='#' \n",
+"li(4)='open(FILEIN,'+ascii(34)+'emp.lst'+ascii(34)+') || die('+ascii(34)+'Cannot open file'+ascii(34)+') ;'\n",
+"li(5)='open(FILEOUT, '+ascii(34)+'>emp_out.lst'+ascii(34)+') ; '\n",
+"li(6)='while(<FILEIN>) { # As long as there are lines in the file '\n",
+"li(7)=' print FILEOUT if (1..3) ; print STDOUT ; # Can also use if ($. < 4) '\n",
+"li(8)='}'\n",
+"li(9)='close(FILEIN); '\n",
+"li(10)='close(FILEOUT); ' \n",
+"li(11)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:9\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=10 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript in Command Line Prompt<-------------- ')\n",
+"printf('\n# Type the following command in command prompt as it appears to check the file is successfully copied\n\n')\n",
+"printf('\n$ type emp_out.lst #to check the contents of the new file\n')\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')\n",
+"mdelete('emp.lst')\n",
+"mdelete('emp_out.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.17: Program_17.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"//Program for example 1 chapter 1\n",
+"printf('Example 17 : Show the method of filetesting in perlscript')\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl '\n",
+"li(2)='# Script: '+nam+'.pl - Find files that are less than 2.4 hours old '\n",
+"li(3)='#' \n",
+"li(4)='foreach $file (`dir /B`) { '\n",
+"li(5)='chop($file) ;'\n",
+"li(6)='if (($m_age = -M $file) < 0.1) { #tenth of a day i.e 2.4 hours'\n",
+"li(7)=' printf '+ascii(34)+' File %s was last modified %0.3f day(s) back \n'+ascii(34)+',$file,$m_age ; '\n",
+"li(8)=' }'\n",
+"li(9)='}'\n",
+"li(10)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:10\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=10 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl [THE NUMBERS AS COMMANDLINE ARGUMENTS] %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl [THE NUMBERS AS COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.18: Program_18.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 18 : Show the method of declaration of subroutines')\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl '\n",
+"li(2)='system('+ascii(34)+'cls'+ascii(34)+') ;# Script: '+nam+'.pl - Shows the use of Subroutines '\n",
+"li(3)='#' \n",
+"li(4)=' system('+ascii(34)+'cls'+ascii(34)+'); #clears the screen'\n",
+"li(5)='$username = &take_input('+ascii(34)+'Oracle user-id: '+ascii(34)+') ;'\n",
+"li(6)='$password = &take_input('+ascii(34)+'Oracle password: '+ascii(34)+', '+ascii(34)+'noecho'+ascii(34)+') ;'\n",
+"li(7)='print '+ascii(34)+'\nThe username and password are $username and $password\n'+ascii(34)+' ;'\n",
+"li(8)=' '\n",
+"li(9)='sub take_input { '\n",
+"li(10)=' my ($prompt,$flag) = @_ ; # @_stores arguments of subroutines '\n",
+"li(11)=' while (1) { # (1) means always true '\n",
+"li(12)=' print('+ascii(34)+'$prompt'+ascii(34)+') ;'\n",
+"li(13)=' use Term::ReadKey;'\n",
+"li(14)=' ReadMode 2 if (@_==2); #turn ehoing off'\n",
+"li(15)=' chop($name=<STDIN>); '\n",
+"li(16)=' ReadMode 0 if (@_==2); #turn echoing on back'\n",
+"li(17)=' last if $name =~ /\w/ ; #Quit if $name has atleast one word character'\n",
+"li(18)=' }'\n",
+"li(19)=' $name ; #return $name will also do'\n",
+"li(20)=' }'\n",
+"li(21)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:20\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" \n",
+" if i==13 then\n",
+" printf('\t system(%c stty -echo%c) if (@_==2) ; #Echo off\n',ascii(34),ascii(34))\n",
+" end\n",
+" if i==16 then\n",
+" printf('\t system(%c stty echo%c) if (@_==2) ; #Echo on\n',ascii(34),ascii(34))\n",
+" end\n",
+" if i~=20&i~=14&i~=13&i~=16 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.1: Program_1.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"pwd\n",
+"curr=ans\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere 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.\nPLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Shows the use of variables'\n",
+"li(3)='#'\n",
+"li(4)='print('+ascii(34)+'Enter your name: '+ascii(34)+') ;' \n",
+"li(5)='$name = <STDIN> ; #Input from the keyboard'\n",
+"li(6)='print('+ascii(34)+'Enter a temperature in Centigrade: '+ascii(34)+') ;'\n",
+"li(7)='$centigrade=<STDIN>; #Whitespace unimportant'\n",
+"li(8)='$fahrenheit=$centigrade*9/5 + 32 ; #Here too ' \n",
+"li(9)='print '+ascii(34)+'The temperature $name in Fahrenheit is $fahrenheit\n'+ascii(34)+' ;'\n",
+"li(10)='print('+ascii(34)+'\n\nType exit to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:10\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=10 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.2: Program_2.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 2 : Show the method of using chop in perl \n\n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere 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.\nPLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Demonstrates use of chop'\n",
+"li(3)='#'\n",
+"li(4)='print('+ascii(34)+'Enter your name: '+ascii(34)+') ;' \n",
+"li(5)='$name = <STDIN> ; '\n",
+"li(6)='chop($name) ; #Removes newline character from $name'\n",
+"li(7)='if ( $name ne '+ascii(34)+ascii(34)+' ) {'+ascii(10)+'print('+ascii(34)+'$name, have a nice day\n'+ascii(34)+');} '\n",
+"li(8)='else {'+ascii(10)+'print('+ascii(34)+'You have not entered your name\n'+ascii(34)+');} '\n",
+"li(9)='print('+ascii(34)+'\n\nType exit to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:9\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=9 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.3: Program_3.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 3 : Show the method of using default variables in perl using \n\t\tmailbox specific extraction as an example \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.\n2. PLEASE MAKE SURE THAT THE PERLSCRIPT INTERPRETER\nEXISTS IN THE SYSTEM\nOR THE COMMAND WOULD NOT WORK \n\n3. THIS IS POSSIBLE ONLY IF THE HOME DIRECTORY CONTAINS MAILBOX PATH\n4. PRESS ENTER AFTER EACH COMMAND to see its RESULT\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Extracts the From: headers from the mailbox'\n",
+"li(3)='#'\n",
+"li(4)='while(<>) { # Actually ($_ = <>) ' \n",
+"li(5)=' chop() ; # chop($_)'\n",
+"li(6)=' if ( /From:.*\@velvet.com/) { # if ($_ =~ /From:.*\@velvet ...) '\n",
+"li(7)=' $slno++ ;'\n",
+"li(8)=' print($slno . '+ascii(34)+' '+ascii(34)+' . $_ . '+ascii(34)+'\n'+ascii(34)+') ;' \n",
+"li(9)=' } } '\n",
+"li(10)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:10\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=10 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl [MAILBOX PATH AS COMMANDLINE ARGUMENT] %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl [MAILBOX PATH-CMDLINE ARGUMENT] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.4: Program_4.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 4 : Show the method of array handling in perl \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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Shows use of arrays'\n",
+"li(3)='#'\n",
+"li(4)='@days_between = ('+ascii(34)+'Wed'+ascii(34)+', '+ascii(34)+'Thu'+ascii(34)+') ;'\n",
+"li(5)='@days = (Mon,Tue,@days_between,Fri) ; '\n",
+"li(6)='@days[5,6] = qw/Sat Sun/ ; '\n",
+"li(7)='$length = @days ; '\n",
+"li(8)='#'\n",
+"li(9)='print('+ascii(34)+'The third day of the week is $days[2]\n'+ascii(34)+') ;'\n",
+"li(10)='print('+ascii(34)+'The days of the week are @days\n'+ascii(34)+') ;'\n",
+"li(11)='print('+ascii(34)+'The number of elements in the array is $length\n'+ascii(34)+') ;'\n",
+"li(12)='print('+ascii(34)+'The last subscript of the array is $#days\n'+ascii(34)+') ;'\n",
+"li(13)='$#days = 5; #Resize the array'\n",
+"li(14)='print('+ascii(34)+'\$days[6] is now $days[6]\n'+ascii(34)+') ;'\n",
+"li(15)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:15\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=15 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.5: Program_5.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 5 : Show the method of command line argument handling in perl \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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Determines whether a year is leap year or not '\n",
+"li(3)='#'\n",
+"li(4)='die('+ascii(34)+'You have not entered the year\n'+ascii(34)+') if (@ARGV == 0 ) ;'\n",
+"li(5)='$year = $ARGV[0] ; # The first argument'\n",
+"li(6)='$last2digits = substr($year,-2,2) ; #Extract from the right '\n",
+"li(7)='if ($last2digits eq '+ascii(34)+'00'+ascii(34)+') {'\n",
+"li(8)=' $yesorno = ($year % 400 == 0 ? '+ascii(34)+'certainly'+ascii(34)+' : '+ascii(34)+'not'+ascii(34)+' ) ;'\n",
+"li(9)='}'\n",
+"li(10)='else {'\n",
+"li(11)=' $yesorno = ($year % 4 == 0 ? '+ascii(34)+'certainly'+ascii(34)+' : '+ascii(34)+'not'+ascii(34)+' ) ;'\n",
+"li(12)=li(9)\n",
+"li(13)='print('+ascii(34)+'$year is '+ascii(34)+' . $yesorno . '+ascii(34)+' a leap year \n'+ascii(34)+') ;'\n",
+"li(14)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:14\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=14 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl [THE YEAR AS COMMANDLINE ARGUMENT] %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl [THE YEAR AS COMMANDLINE ARGUMENT] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.6: Program_6.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 6 : Show the method of looping using %cforeach%c in perl \n',ascii(39),ascii(39))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Finds the square root of each command line argument '\n",
+"li(3)='#'\n",
+"li(4)='print('+ascii(34)+'The program you are running is $0\n'+ascii(34)+') ;'\n",
+"li(5)='foreach $number (@ARGV) { # Each element of $ARGV goes to $number '\n",
+"li(6)=' print('+ascii(34)+'The square root of $number is '+ascii(34)+' . sqrt($number) . '+ascii(34)+'\n'+ascii(34)+') ;'\n",
+"li(7)='}'\n",
+"li(8)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:8\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=8 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl [THE NUMBERS AS COMMANDLINE ARGUMENTS] %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl [THE NUMBERS AS COMMANDLINE ARGUMENTS] #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.7: Program_7.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 7 : Show the method of splititng a string using %csplit%c in perl \n',ascii(39),ascii(39))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Finds the square root of each command line argument '\n",
+"li(3)='#'\n",
+"li(4)='print('+ascii(34)+'Enter three numbers: '+ascii(34)+' ) ; '\n",
+"li(5)='chop($numstring=<STDIN>) ;'\n",
+"li(6)='die('+ascii(34)+'Nothing entered\n'+ascii(34)+') if ($numstring eq '+ascii(34)+ascii(34)+' ) ;'\n",
+"li(7)='($f_number,$s_number,$l_number) = split(/ /,$numstring) ;'\n",
+"li(8)='print('+ascii(34)+'The last, second and first numbers are '+ascii(34)+') ;'\n",
+"li(9)='print('+ascii(34)+'$l_number,$s_number and $f_number.\n'+ascii(34)+') ;'\n",
+"li(10)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:10\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=10 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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 perl %s.pl %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ perl %s.pl #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.8: Program_8.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"printf('Example 8 : Show the method of splitting a string to an array using %csplit%c in perl \n',ascii(39),ascii(39))\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\n6.Afile named %cemp.lst%c with the necessary details gets created automatically for the session',ascii(34),ascii(34))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl'\n",
+"li(2)='# Script: '+nam+'.pl - Uses split twice; prints with first and last name reversed '\n",
+"li(3)='#'\n",
+"li(4)='while (<>) {'\n",
+"li(5)=' chop; '\n",
+"li(6)=' @field = split(/\|/) ; # $_ is used by default '\n",
+"li(7)=' if (1..4) { # Lines 1 to 4 '\n",
+"li(8)=' $dept = $field[3] ; $name = $field[1] ; $salary = $field[5] ;'\n",
+"li(9)=' ($f_name,$l_name) = split(/ +/,$name) ; '\n",
+"li(10)=' $name = $l_name . '+ascii(34)+', '+ascii(34)+' . $f_name ; #Reusing $name'\n",
+"li(11)=' $totsal += $salary ;'\n",
+"li(12)=' printf('+ascii(34)+'%3d %-20s %-11s %4d\n'+ascii(34)+', $. ,$name , $dept ,$salary ) ;'\n",
+"li(13)=' }'\n",
+"li(14)=' }'\n",
+"li(15)='printf('+ascii(34)+'%35s %5d\n'+ascii(34)+','+ascii(34)+'Total Salary: '+ascii(34)+', $totsal) ;'\n",
+"li(16)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:16\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=16 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl emp.lst %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl emp.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 19.9: Program_9.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"curr=ans\n",
+"clc\n",
+"//Program for example 1 chapter 1\n",
+"printf('Example 9 : Show the method of joining an array using %cjoin%c in perl \n',ascii(39),ascii(39))\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\n6.A file named %cemp.lst%c with the necessary details gets created automatically for the session',ascii(34),ascii(34))\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",
+"printf('\n# Enter the name of the perlscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"clc\n",
+"li(1)='#!/usr/bin/perl -n '\n",
+"li(2)='# Script: '+nam+'.pl - Uppercases the name and adds century prefix to the date '\n",
+"li(3)='#'\n",
+"li(4)='@line = split(/\|/) ; # $_ is assumed '\n",
+"li(5)='($day, $month, $year) = split(/\// , $line[4]); # Splits date field'\n",
+"li(6)='$year = '+ascii(34)+'19'+ascii(34)+' . $year ; # Adds century prefix'\n",
+"li(7)='$line[4] = join('+ascii(34)+'\/'+ascii(34)+', $day , $month , $year) ; # Rebuilds date field'\n",
+"li(8)='$line = join('+ascii(34)+'\|'+ascii(34)+', @line); # Rebuilds line'\n",
+"li(9)='print $line; '\n",
+"li(10)='print('+ascii(34)+'\n\nType'+ascii(39)+'exit'+ascii(39)+'to go back to console\n\n'+ascii(34)+')'\n",
+"halt(' ')\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:9\n",
+" mfprintf(v,'%s\n',li(i))\n",
+" if i~=10 then\n",
+" printf('%s\n',li(i))\n",
+" end\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease open a new terminal window and then go to the directory %s and execute the following instruction\n\nperl %s.pl [Command line parameters if any]\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.pl emp.lst %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s.pl emp.lst #to execute the perlscript',nam)\n",
+"halt(' ')\n",
+"dos('start')\n",
+"printf('\n\n\n')\n",
+"halt(' ---------------->Executing PerlScript 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+'.pl')\n",
+"mdelete('emp.lst')"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/2-The_Unix_Architecture_and_Command_Usage.ipynb b/Unix_Concepts_And_Applications_by_S_Das/2-The_Unix_Architecture_and_Command_Usage.ipynb
new file mode 100644
index 0000000..7b280d7
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/2-The_Unix_Architecture_and_Command_Usage.ipynb
@@ -0,0 +1,248 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 2: The Unix Architecture and Command Usage"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.1: Shell_Name.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear()\n",
+"clc\n",
+"disp('Example 1 : Display the current working shell ')\n",
+"disp('***************************************************************************')\n",
+"disp('Answer : ')\n",
+"printf('The current Working Shell is ')\n",
+"if (getos()=='Linux') then\n",
+" unix_w('echo $SHELL')\n",
+"else\n",
+" printf('%s',getshell())\n",
+"end\n",
+"disp('***************************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.2: Type_of_keywords.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 2 chapter 2\n",
+"clear\n",
+"clc\n",
+"disp('Example 2: Display the type of a given variable or a command ')\n",
+"disp('')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer :')\n",
+"printf('THE FOLLOWING LINES OF CODE RUN \nONLY IN SCILAB INSTALLED IN UNIX ENVIRONMENT.....')\n",
+"printf('\nTHE CONSOLE GIVES DIFFERENT \nOUTPUT IN OTHER OPERATING SYSTEMS')\n",
+"if(getos() ~= 'Linux' )then\n",
+" ctd=input('Enter the command or variable whose type is to be determined ')\n",
+" clc(1)\n",
+" pt = input('Enter the command again to confirm ','s')\n",
+" clc(1)\n",
+" printf('Continue?....\ny :Yes\nAny other key:No')\n",
+" st = input('','s')\n",
+" clc(2)\n",
+" if( st ~= 'y') then\n",
+" exit\n",
+" else\n",
+" n=type(ctd)\n",
+" clc(1)\n",
+" printf('%s is a ',pt)\n",
+" select n\n",
+"case 1 then\n",
+"printf('a real or complex matrix of double.')\n",
+"case 2 then\n",
+"printf('a polynomial matrix.')\n",
+"case 4 then\n",
+"printf('a boolean matrix.')\n",
+"case 5 then\n",
+"printf('a sparse matrix.')\n",
+"case 6 then\n",
+"printf('a sparse boolean matrix.')\n",
+"case 7 then\n",
+"printf('Matlab sparse matrix')\n",
+"case 8 then\n",
+"printf('a matrix of integers stored on 1 (int8), 2 (int16) or 4 (int32) bytes.')\n",
+"case 9 then\n",
+"printf('a matrix of graphic handles.')\n",
+"case 10 then\n",
+"printf('a matrix of character strings.')\n",
+"case 11 then\n",
+"printf('an un-compiled function . A function created with deff with argument [n].')\n",
+"case 13 then\n",
+"printf('a compiled function .')\n",
+"case 14 then\n",
+"printf('a function library.')\n",
+"case 15 then\n",
+"printf('a list.')\n",
+"case 16 then\n",
+"printf('a typed list (tlist).')\n",
+"case 17 then\n",
+"printf('a matrix oriented typed list (mlist).')\n",
+"case 128 then\n",
+"printf('a pointer (Use case: lufact).')\n",
+"case 129 then\n",
+"printf('a size implicit polynomial used for indexing.')\n",
+"case 130 then\n",
+"printf('a built-in Scilab function, called also gateway (C, C++ or Fortran code).')\n",
+"case 0 then\n",
+"printf('a null variable. It is mainly used internally by Scilab. If a function has no declared returned argument like disp when it is called it returns a null variable. If a function is called with an omitted argument in the argument list like foo(a,,b) the missing argument is assigned to a null variable.')\n",
+" end\n",
+" end\n",
+"else\n",
+" disp('Enter the file whose type is to be found')\n",
+" unix_w('read xtun;type $xtun')\n",
+"end\n",
+"printf('\n*******************************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.3: Path_Variable.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"disp('Example 3 : Display the value of the path variable of the current command interpreter')\n",
+"disp('*************************************************************************')\n",
+"disp('Answer :')\n",
+"printf('THE FOLLOWING LINES OF CODE RUN \nONLY IN SCILAB INSTALLED IN UNIX ENVIRONMENT.....')\n",
+"printf('\nTHE CONSOLE GIVES DIFFERENT \nOUTPUT IN OTHER OPERATING SYSTEMS\n\n')\n",
+"halt('Continue ?? ? ...')\n",
+"if (getos() ~= 'Linux' ) then\n",
+" printf('The value of PATH variable is %s',SCIHOME)\n",
+"else\n",
+" unix_w('echo The value of path variable is $PATH')\n",
+"end\n",
+"disp('****************************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.4: Option_using.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"printf('Example 4 : Show the usage of options in commands by \n\t\ttaking long listing(or detailed file listing)) ls -l as an example')\n",
+"disp('*************************************************************************')\n",
+"disp('Answer : ')\n",
+"halt('Continue ?? ? ...')\n",
+"if (getos() ~= 'Linux' ) then\n",
+" printf('The details of files in the current directory are \n')\n",
+" powershell('ls')\n",
+"else\n",
+" unix_w('echo The details of files in the current directory are ; ls -l')\n",
+"end\n",
+"disp('****************************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 2.5: Man_Pages.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"clc\n",
+"disp('Example 5: Display all the manual pages related to a particular entered keyword ')\n",
+"printf('\n*******************************************************************\n')\n",
+"disp('Answer : ')\n",
+"disp('')\n",
+"printf('THE FOLLOWING LINES OF CODE RUN \nONLY IN SCILAB INSTALLED IN UNIX ENVIRONMENT.....')\n",
+"printf('\nTHE CONSOLE GIVES DIFFERENT \nOUTPUT IN OTHER OPERATING SYSTEMS\n\n')\n",
+"halt('Continue ?? ? ...')\n",
+"if (getos() ~= 'Linux' ) then\n",
+" st=input('Enter the keyword to be found in the HELP pages : ','string')\n",
+" clc(1)\n",
+" apropos(st)\n",
+"else\n",
+" disp('Enter the keyword whose man pages are to be shown : ')\n",
+" unix_w('read stx;man $stx')\n",
+"end\n",
+"disp('****************************************************************************')\n",
+" "
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/21-Advanced_Shell_Programming.ipynb b/Unix_Concepts_And_Applications_by_S_Das/21-Advanced_Shell_Programming.ipynb
new file mode 100644
index 0000000..42d9b84
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/21-Advanced_Shell_Programming.ipynb
@@ -0,0 +1,564 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 21: Advanced Shell Programming"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 21.1: Program_1.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 1 : Show the method of using arrays in advanced shellscripting \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",
+"i=0\n",
+"i=i+1;f(i)='#!/usr/bin/ksh'\n",
+"i=i+1;f(i)='# Script: dateval.sh - validates a date field using an array'\n",
+"i=i+1;f(i)='IFS='+ascii(34)+'/'+ascii(34)+''\n",
+"i=i+1;f(i)='n='+ascii(34)+'[0-9][0-9]'+ascii(34)+''\n",
+"i=i+1;f(i)='set -A month arr 0 31 29 31 30 31 30 31 30 31 30 31'\n",
+"i=i+1;f(i)='while echo '+ascii(34)+'Enter a date: \c'+ascii(34)+' ; do'\n",
+"i=i+1;f(i)=' read value'\n",
+"i=i+1;f(i)=' case '+ascii(34)+'$value'+ascii(34)+' in'\n",
+"i=i+1;f(i)=' '+ascii(34)+''+ascii(34)+') echo '+ascii(34)+'No date entered'+ascii(34)+' ; continue ;;'\n",
+"i=i+1;f(i)=' $n/$n/$n) set $value'\n",
+"i=i+1;f(i)=' let rem='+ascii(34)+'$3 % $4'+ascii(34)+''\n",
+"i=i+1;f(i)=' if [ $2 -gt 12 -o $2 -eq 0 ] ; then'\n",
+"i=i+1;f(i)=' echo '+ascii(34)+'Illegal month'+ascii(34)+' ; continue'\n",
+"i=i+1;f(i)=' else'\n",
+"i=i+1;f(i)=' case '+ascii(34)+'$value'+ascii(34)+' in'\n",
+"i=i+1;f(i)=' 29/02/??) [ $rem -gt 0 ] &&'\n",
+"i=i+1;f(i)=' { echo '+ascii(34)+'20$3 is not a leap year'+ascii(34)+' ; continue ; } ;;'\n",
+"i=i+1;f(i)=' *) [ $1 -gt ${month_arr[$2]} -o $1 -eq 0 ] &&'\n",
+"i=i+1;f(i)=' { echo '+ascii(34)+'Illegal day'+ascii(34)+' ; continue ; } ;;'\n",
+"i=i+1;f(i)=' esac'\n",
+"i=i+1;f(i)=' fi;;'\n",
+"i=i+1;f(i)=' *) echo '+ascii(34)+'Invalid date'+ascii(34)+' ; continue ;;'\n",
+"i=i+1;f(i)=' esac'\n",
+"i=i+1;f(i)=' echo '+ascii(34)+'$1/$2/$3'+ascii(34)+' is a valid date'\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)='set chc=y'\n",
+"i=i+1;f(i)=':loop'\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%chc%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endloop'\n",
+"i=i+1;f(i)='set /P dat=Enter a date: '\n",
+"i=i+1;f(i)='if '+ascii(34)+'%dat%'+ascii(34)+' equ '+ascii(34)+''+ascii(34)+' echo No date entered&&goto chci'\n",
+"i=i+1;f(i)='if exist testt del testt'\n",
+"i=i+1;f(i)='echo %dat%>testt'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'tokens=1,2,3 delims=/'+ascii(34)+' %%i in (testt) do set dd=%%i&&set mm=%%j&&set yy=%%k'\n",
+"i=i+1;f(i)='if %mm% gtr 12 echo Illegal month&&goto chci'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'01'+ascii(34)+' set ulim=31&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'03'+ascii(34)+' set ulim=31&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'04'+ascii(34)+' set ulim=30&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'05'+ascii(34)+' set ulim=31&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'06'+ascii(34)+' set ulim=30&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'07'+ascii(34)+' set ulim=31&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'08'+ascii(34)+' set ulim=31&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'09'+ascii(34)+' set ulim=30&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'10'+ascii(34)+' set ulim=31&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'11'+ascii(34)+' set ulim=30&&goto printing'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%mm%'+ascii(34)+'=='+ascii(34)+'12'+ascii(34)+' set ulim=31&&goto printing'\n",
+"i=i+1;f(i)='set /a rem=yy%%4'\n",
+"i=i+1;f(i)='if %rem% neq 0 set ulim=28&&goto nlpyear'\n",
+"i=i+1;f(i)='set ulim=29'\n",
+"i=i+1;f(i)='goto printing'\n",
+"i=i+1;f(i)=':nlpyear'\n",
+"i=i+1;f(i)='if '+ascii(34)+'%dd%'+ascii(34)+'=='+ascii(34)+'29'+ascii(34)+' echo 20%yy% is not a leap year&&goto chci'\n",
+"i=i+1;f(i)=':printing'\n",
+"i=i+1;f(i)='if %dd% leq %ulim% echo %dat% is a valid date&&goto chci'\n",
+"i=i+1;f(i)='echo Illegal day '\n",
+"i=i+1;f(i)=':chci'\n",
+"i=i+1;f(i)='set /p chc=Do you want to 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&&del testt'\n",
+"n=i\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute using the instructions\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('emp.lst')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 21.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 calling functions in shellscripts \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",
+"i=0\n",
+"i=i+1;f(i)='#! /bin/sh'\n",
+"i=i+1;f(i)='# Script: user_passwd.sh - Uses a shell function'\n",
+"i=i+1;f(i)='#'\n",
+"i=i+1;f(i)='.mainfunc.sh # Script containing valid_string function'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='valid_string() {'\n",
+"i=i+1;f(i)=' while echo '+ascii(34)+'$1 \c'+ascii(34)+' 1>&2 ; do'\n",
+"i=i+1;f(i)=' read name'\n",
+"i=i+1;f(i)=' case $name in'\n",
+"i=i+1;f(i)=' '+ascii(34)+''+ascii(34)+') echo '+ascii(34)+'Nothing entered'+ascii(34)+' 1>&2 ; continue ;;'\n",
+"i=i+1;f(i)=' *) if [ `expr '+ascii(34)+'$name'+ascii(34)+' : '+ascii(39)+'.*'+ascii(39)+'` -gt $2 ] ; then'\n",
+"i=i+1;f(i)=' echo '+ascii(34)+'Maximum $2 characters permitted'+ascii(34)+' 1>&2'\n",
+"i=i+1;f(i)=' else'\n",
+"i=i+1;f(i)=' break'\n",
+"i=i+1;f(i)=' fi ;;'\n",
+"i=i+1;f(i)=' esac'\n",
+"i=i+1;f(i)=' done'\n",
+"i=i+1;f(i)=' echo $name'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='user=`valid_string '+ascii(34)+'Enter your user-id :'+ascii(34)+' 16`'\n",
+"i=i+1;f(i)='stty -echo # Password not to be echoed'\n",
+"i=i+1;f(i)='password=`valid_string '+ascii(34)+'Enter your password:'+ascii(34)+' 5`'\n",
+"i=i+1;f(i)='stty echo # Turns on echoing facility'\n",
+"i=i+1;f(i)='echo '+ascii(34)+'\nYour user-id is $user and your password is $password'+ascii(34)+''\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)='#!/usr/bin/perl' \n",
+"i=i+1;f(i)='$username = &take_input('+ascii(34)+'Enter your user-id: '+ascii(34)+', '+ascii(34)+'16'+ascii(34)+') ;'\n",
+"i=i+1;f(i)='$password = &take_input('+ascii(34)+'Enter your password: '+ascii(34)+', '+ascii(34)+'5'+ascii(34)+','+ascii(34)+'noecho'+ascii(34)+') ;'\n",
+"i=i+1;f(i)='print '+ascii(34)+'\nYour user-id is $username and your password is $password\n'+ascii(34)+' ;'\n",
+"i=i+1;f(i)='sub take_input { '\n",
+"i=i+1;f(i)='my ($prompt,$len,$flag) = @_ ;' \n",
+"i=i+1;f(i)='while (1) { '\n",
+"i=i+1;f(i)='print('+ascii(34)+'$prompt'+ascii(34)+') ;'\n",
+"i=i+1;f(i)='use Term::ReadKey;'\n",
+"i=i+1;f(i)='ReadMode 2 if (@_==3);'\n",
+"i=i+1;f(i)='chop($name=<STDIN>); '\n",
+"i=i+1;f(i)='ReadMode 0 if (@_==3);'\n",
+"i=i+1;f(i)='if ( length($name) eq 0 ) { printf '+ascii(34)+'\nNothing entered\n'+ascii(34)+' ; next }'\n",
+"i=i+1;f(i)='if ( length($name) > $len) { printf '+ascii(34)+'Maximum %d characters permitted\n'+ascii(34)+' , $len ; next }'\n",
+"i=i+1;f(i)='last if $name =~ /\w/ ;'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)='$name ;'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"v=mopen(nam+'.pl','wt')\n",
+"for i=1:n\n",
+" mfprintf(v,'%s\n',f(i))\n",
+"end\n",
+"mclose(v)\n",
+"i=0\n",
+"i=i+1;f(i)='@echo off'\n",
+"i=i+1;f(i)=nam+'.pl'\n",
+"i=i+1;f(i)='pause>NUL'\n",
+"i=i+1;f(i)='del '+nam+'.pl'\n",
+"n=i\n",
+"v=mopen(nam+'.bat','wt')\n",
+"for i=1:n\n",
+" mfprintf(v,'%s\n',f(i))\n",
+"end\n",
+"mclose(v)\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute using the instructions\n\nThank You \n\n')\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 %c[ENTER]\n\n',ascii(34),nam,ascii(34))\n",
+"printf('\n$ %s #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+'.bat')\n",
+"mdelete('emp.lst')\n",
+"mdelete(nam+'.pl')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 21.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 eval in the shellscripts \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\n4. 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",
+"printf('\n# Enter the name of the shellscript file whichever you desire \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"halt(' ')\n",
+"i=0\n",
+"i=i+1;f(i)='#!/bin/sh'\n",
+"i=i+1;f(i)='# Script: dentry2.sh - Uses eval and shell functions'\n",
+"i=i+1;f(i)='#'\n",
+"i=i+1;f(i)='trap '+ascii(39)+'echo '+ascii(34)+'Program interrupted'+ascii(34)+';exit'+ascii(39)+' HUP INT TERM'\n",
+"i=i+1;f(i)='. mainfunc.sh # Invokes functions valid_string() and anymore ()'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='prompt1='+ascii(34)+'Employee id : '+ascii(34)+' ; prompt2='+ascii(34)+'Name : '+ascii(34)+'; prompt3='+ascii(34)+'Designation : '+ascii(34)+''\n",
+"i=i+1;f(i)='prompt4='+ascii(34)+'Department : '+ascii(34)+' ; prompt5='+ascii(34)+'Date birth : '+ascii(34)+';prompt6='+ascii(34)+'Basic pay : '+ascii(34)+''\n",
+"i=i+1;f(i)='rekord='\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='flname=`valid_string '+ascii(34)+'Enter the output filename: '+ascii(34)+' 8`'\n",
+"i=i+1;f(i)='while true ; do'\n",
+"i=i+1;f(i)=' while [ ${x:=1} -le 6 ] ; do # x first set to 1'\n",
+"i=i+1;f(i)=' eval echo \$prompt$x '+ascii(39)+'\\c'+ascii(39)+' 1>&2'\n",
+"i=i+1;f(i)=' read value$x'\n",
+"i=i+1;f(i)=' rekord='+ascii(34)+'${rekord}`eval echo \\$value$x`|'+ascii(34)+''\n",
+"i=i+1;f(i)=' x=`expr $x + 1`'\n",
+"i=i+1;f(i)=' done'\n",
+"i=i+1;f(i)=' echo '+ascii(34)+'$rekord'+ascii(34)+''\n",
+"i=i+1;f(i)=' anymore '+ascii(34)+'More entries to add'+ascii(34)+' 1&>2 || break'\n",
+"i=i+1;f(i)='done > $flname'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='anymore() {'\n",
+"i=i+1;f(i)=' echo '+ascii(34)+'\n$1 ?(y/n) : \c'+ascii(34)+' 1>&2'\n",
+"i=i+1;f(i)=' read response'\n",
+"i=i+1;f(i)=' case '+ascii(34)+'$response'+ascii(34)+' in'\n",
+"i=i+1;f(i)=' y/Y) echo 1>&2 ; return 0 ;;'\n",
+"i=i+1;f(i)=' *) return 1 ;;'\n",
+"i=i+1;f(i)=' esac'\n",
+"i=i+1;f(i)='}'\n",
+"n=i \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)='set /P flname=Enter the output filename: '\n",
+"i=i+1;f(i)='if exist %flname% del %flname%'\n",
+"i=i+1;f(i)='set response=y'\n",
+"i=i+1;f(i)=':loop'\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%response%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endloop'\n",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='set /P eid=Employee id : '\n",
+"i=i+1;f(i)='set /P nam=Name : '\n",
+"i=i+1;f(i)='set /P desig=Designation : '\n",
+"i=i+1;f(i)='set /P dept=Department : '\n",
+"i=i+1;f(i)='set /P dob=Date birth : '\n",
+"i=i+1;f(i)='set /P bas=Basic pay : '\n",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='echo %eid%:%nam%:%desig%:%dept%:%dob%:%bas%:>>%flname%'\n",
+"i=i+1;f(i)='set /P response=More entries to add ?(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",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='set /p res2= Do you want to see the file %flname%?(y/n) : '\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%res2%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endd'\n",
+"i=i+1;f(i)='echo $ cat %flname%'\n",
+"i=i+1;f(i)='type %flname%'\n",
+"i=i+1;f(i)=':endd'\n",
+"i=i+1;f(i)='pause>NUL' \n",
+"n=i\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute using the instructions\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[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 21.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 exec command to make many streams \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",
+"i=0\n",
+"i=i+1;f(i)='#!/bin/sh'\n",
+"i=i+1;f(i)='# Script: countpat.sh -- Uses exec to handle multiple files'\n",
+"i=i+1;f(i)='#'\n",
+"i=i+1;f(i)='exec > $2 # Open file 1 for storing selected lines'\n",
+"i=i+1;f(i)='exec 3> $3 # Open file 3 for storing patterns not found'\n",
+"i=i+1;f(i)='exec 4> $4 # Open file 4 for storing invalid patterns'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='[ $# -ne 4 ] && { echo '+ascii(34)+'4 arguments required'+ascii(34)+' ; exit 2 ; }'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='exec < $1 # Redirecting output'\n",
+"i=i+1;f(i)='while read pattern ; do '\n",
+"i=i+1;f(i)=' case '+ascii(34)+'$pattern'+ascii(34)+' in'\n",
+"i=i+1;f(i)=' ????) grep $pattern emp.lst ||'\n",
+"i=i+1;f(i)=' echo $pattern not found in file 1>&3 ;;'\n",
+"i=i+1;f(i)=' *) echo $pattern not a four-character string 1>&4 ;;'\n",
+"i=i+1;f(i)=' esac'\n",
+"i=i+1;f(i)='done'\n",
+"i=i+1;f(i)='exec > \/dev/tty # Redirects standard output back to terminal'\n",
+"i=i+1;f(i)='echo Job Over'\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)='for %%x in (%*) do set /a ccc+=1'\n",
+"i=i+1;f(i)='if %ccc% neq 4 echo 4 arguments required&&goto endd'\n",
+"i=i+1;f(i)='echo.'\n",
+"i=i+1;f(i)='echo -----------Creating file %1-----------------'\n",
+"i=i+1;f(i)='set chice=y'\n",
+"i=i+1;f(i)=':loop1'\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%chice%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endloop1'\n",
+"i=i+1;f(i)='set /P inp=Enter the employee-id : '\n",
+"i=i+1;f(i)='echo %inp%>>%1'\n",
+"i=i+1;f(i)='if exist len del len'\n",
+"i=i+1;f(i)='echo.%inp%>len'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%i in ('+ascii(39)+'len'+ascii(39)+') do set len=%%~zi'\n",
+"i=i+1;f(i)='del len&&set /a len-=2'\n",
+"i=i+1;f(i)='if %len% neq 4 echo %inp% is not a four-character string>>%4&&goto chi'\n",
+"i=i+1;f(i)='if exist res del res'\n",
+"i=i+1;f(i)='findstr /B '+ascii(34)+'%inp%'+ascii(34)+' emp.lst>res'\n",
+"i=i+1;f(i)='for /F '+ascii(34)+'usebackq'+ascii(34)+' %%i in ('+ascii(39)+'res'+ascii(39)+') do set siz=%%~zi'\n",
+"i=i+1;f(i)='if %siz% equ 0 echo %inp% not found in file>>%3&&goto chi'\n",
+"i=i+1;f(i)='type res>>%2'\n",
+"i=i+1;f(i)=':chi'\n",
+"i=i+1;f(i)='set /P chice=Do you want to continue?(y/n) : '\n",
+"i=i+1;f(i)='cls&&goto loop1'\n",
+"i=i+1;f(i)=':endloop1'\n",
+"i=i+1;f(i)='set /P c1=Do you want to see the file %1?(y/n) : '\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%c1%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endloop2'\n",
+"i=i+1;f(i)='type %1'\n",
+"i=i+1;f(i)=':endloop2'\n",
+"i=i+1;f(i)='set /P c2=Do you want to see the file %2?(y/n) : '\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%c2%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endloop3'\n",
+"i=i+1;f(i)='type %2'\n",
+"i=i+1;f(i)=':endloop3'\n",
+"i=i+1;f(i)='set /P c3=Do you want to see the file %3?(y/n) : '\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%c3%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endloop4'\n",
+"i=i+1;f(i)='type %3'\n",
+"i=i+1;f(i)=':endloop4'\n",
+"i=i+1;f(i)='set /P c4=Do you want to see the file %4?(y/n) : '\n",
+"i=i+1;f(i)='if /I '+ascii(34)+'%c4%'+ascii(34)+'=='+ascii(34)+'n'+ascii(34)+' goto endloop2'\n",
+"i=i+1;f(i)='type %4'\n",
+"i=i+1;f(i)=':endloop5'\n",
+"i=i+1;f(i)='pause>NUL&&del %1&&del %2&&del %3&&del %4&&del res'\n",
+"n=i\n",
+"if getos()=='Linux' then\n",
+" printf('\n\nPlease Switch to windows and then execute using the instructions\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('emp.lst')"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/23-Systems_Programming_1_Files.ipynb b/Unix_Concepts_And_Applications_by_S_Das/23-Systems_Programming_1_Files.ipynb
new file mode 100644
index 0000000..62a2ed6
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/23-Systems_Programming_1_Files.ipynb
@@ -0,0 +1,1245 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 23: Systems Programming 1 Files"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 method of listing only directories in systems programming \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program lsdir.c -- Lists only directories using S_IFMT and S_ISDR macros */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <sys/types.h>'\n",
+"i=i+1;f(i)='#include <sys/stat.h>'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <dirent.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc,int **argv){'\n",
+"i=i+1;f(i)=' DIR *dir;'\n",
+"i=i+1;f(i)=' struct dirent *direntry; /* Returned by readdir() */'\n",
+"i=i+1;f(i)=' struct stat statbuf; /* Address of statbuf used by lstat() */'\n",
+"i=i+1;f(i)=' mode_t file_type, file_perm;'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if ((dir = opendir(argv[1])) == NULL)'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'Couldn'+ascii(39)+'t open directory'+ascii(34)+',1);'\n",
+"i=i+1;f(i)=' if((chdir(argv[1]) == -1)) /* Change to directory before */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'chdir'+ascii(34)+',2); /* you starting reading its entries*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' while ((direntry = readdir(dir)) != NULL) { /* Read each entry in directory*/'\n",
+"i=i+1;f(i)=' if (lstat(direntry->d_name,&statbuf) < 0){ /* dname must be in */'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'lstat'+ascii(34)+'); /*current directory */'\n",
+"i=i+1;f(i)=' continue;'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' if (S_ISDIR(statbuf.st_mode)) { /*If file is a directory */'\n",
+"i=i+1;f(i)=' file_type = statbuf.st_mode & S_IFMT;'\n",
+"i=i+1;f(i)=' file_perm = statbuf.st_mode & -S_IFMT;'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'%o %4o %s\n'+ascii(34)+', file_type, file_perm, direntry->d_name);'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat lsdir.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('lsdir.c','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",
+"halt(' ')\n",
+" printf('$ cc lsdir.c')\n",
+" halt(' ')\n",
+" printf('\n# Enter the name of the directory as command-line argument which you want to access \n')\n",
+" nam=input('$ a.out ','s')\n",
+" halt(' ')\n",
+" pwd\n",
+" back=ans\n",
+" cd(nam)\n",
+"x=dir()\n",
+"mprintf('40000 755 %s\n',x.name)\n",
+"cd(back) \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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 method of listing all the permissions in a file \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: check_all_perm.c -- Checks all 12 permission bits of a file */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <sys/stat.h>'\n",
+"i=i+1;f(i)='#include <fcntl.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void print_permissions(char *,struct stat *) ;'\n",
+"i=i+1;f(i)='void check_permission(int, int, char *);'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc,char *argv[]) {'\n",
+"i=i+1;f(i)=' int i,fd,perm;'\n",
+"i=i+1;f(i)=' char *filename = argv[1];'\n",
+"i=i+1;f(i)=' struct stat statbuf;'\n",
+"i=i+1;f(i)=' mode_t perm_flag[] = {S_IRUSR,S_IWUSR,S_IXUSR,S_IRGRP,S_IWGRP,S_IXGRP,S_IROTH,S_IWOTH,S_IXOTH,S_ISUID,S_ISGID,S_ISVTX );'\n",
+"i=i+1;f(i)='' \n",
+"i=i+1;f(i)=' char *mesg[] = {'+ascii(34)+'User-readable'+ascii(34)+','+ascii(34)+'User-writable'+ascii(34)+','+ascii(34)+'User-executable'+ascii(34)+','+ascii(34)+'Group-readable'+ascii(34)+','+ascii(34)+'Group-writable'+ascii(34)+','+ascii(34)+'Group-executable'+ascii(34)+','+ascii(34)+'Others-readable'+ascii(34)+','+ascii(34)+'Others-writable'+ascii(34)+','+ascii(34)+'Others-executable'+ascii(34)+','+ascii(34)+'SUID bit set'+ascii(34)+','+ascii(34)+'SGID bit set'+ascii(34)+','+ascii(34)+'Sticky bit set'+ascii(34)+' );'\n",
+"i=i+1;f(i)='' \n",
+"i=i+1;f(i)=' print_permissions(filename,&statbuf);'\n",
+"i=i+1;f(i)=' ' \n",
+"i=i+1;f(i)=' perm = statbuf.st_mode & -S_IFMT;'\n",
+"i=i+1;f(i)=' for(i = 0; i < 12;i ++)'\n",
+"i=i+1;f(i)=' check_permissions(perm, perm_flag[i], mesg[i]);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat check_all_perm.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('check_all_perm.c','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",
+"halt(' ')\n",
+" printf('$ cc check_all_perm.c')\n",
+" halt(' ')\n",
+" \n",
+" printf('\n$ a.out /usr/bin/passwd ')\n",
+" halt(' ')\n",
+" printf('\nFile: /usr/bin/passwd Permissions: 4511\nUser-readable\nUser-executable\nGroup-executable\nOthers-executable\nSUID bit set\n')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 file access rights of a file using the read UID and GID \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/*Program: faccess.c -- Determines a file'+ascii(39)+'s access rigths using read UID and GID */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *,int);'\n",
+"i=i+1;f(i)='int main(int argc, char *argv[]) {'\n",
+"i=i+1;f(i)=' short count;'\n",
+"i=i+1;f(i)=' for (count = 1; count < argc ;++count) {'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'%s '+ascii(34)+',argv[count]);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (access(argv[count],F_OK) == -1)'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'File not found'+ascii(34)+',1);'\n",
+"i=i+1;f(i)=' if (access(argv[count],R_OK) == -1)'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Not readable '+ascii(34)+');'\n",
+"i=i+1;f(i)=' if (access(argv[count],W_OK) == -1)'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Not writable '+ascii(34)+');'\n",
+"i=i+1;f(i)=' if (access(argv[count],X_OK) == -1)'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Not executable '+ascii(34)+');'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat faccess.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('faccess.c','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",
+"halt(' ')\n",
+" printf('$ cc faccess.c')\n",
+" halt(' ')\n",
+" printf('$ a.out /etc/passwd /etc/shadow')\n",
+" halt(' ')\n",
+"printf('/etc/passwd: Not writable Not executable\n/etc/shadow: Not readable Not writable Not executable\n\n');\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.13: Program_13.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 13 : Show the method of setting a file timestamps \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: atimemtime.c -- Sets a file time stamps to those of another file */'\n",
+"i=i+1;f(i)='#include <sys/stat.h>'\n",
+"i=i+1;f(i)='#include <fcntl.h>'\n",
+"i=i+1;f(i)='#include <utime.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *,int);'\n",
+"i=i+1;f(i)='int main(int argc,char **argv) {'\n",
+"i=i+1;f(i)=' struct stat statbuf; /* To obtain time stamps for an existing file */'\n",
+"i=i+1;f(i)=' struct utimbuf timebuf; /* To set time stamps for another file */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (lstat(argv[1], &statbuf) == -1)'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'stat'+ascii(34)+', 1);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' timebuf.actime = statbuf.st_atime; /* Setting members of timebuf with */'\n",
+"i=i+1;f(i)=' timebuf.modtime= statbuf.st_mtime; /* values obtained from statbuf */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (open(argv[2], O_RWR | O_CREAT, 0644) == -1)'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'open'+ascii(34)+', 2);'\n",
+"i=i+1;f(i)=' close(argv[2]); /* Previously used open only to create it */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (utime(argv[2]), &timebuf) == -1) /* Sets both time stamps for file */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'utime'+ascii(34)+', 3);'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat atimemtime.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('atimemtime.c','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",
+"halt(' ')\n",
+" printf('$ cc atimemtime.c')\n",
+" halt(' ')\n",
+" printf('$ mv a.out $HOME;cd;a.out .profile .logintime')\n",
+" halt(' ')\n",
+" printf('$ ls -l .logintime ; ls -lu .logintime')\n",
+" halt(' ')\n",
+" printf('-rw-r--r-- 1 <user> <group> 0 Jun 20 00:55 .logintime\n')\n",
+" printf('-rw-r--r-- 1 <user> <group> 0 Jun 5 00:30 .logintime\n')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.1: Program_1.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 1 : Show the method of copying files with the read and write system calls \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program ccp.c -- Copies a file with the read and write system calls */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <fcntl.h> /* For O_RDONLY , O_WRONLY , O_CREAT etc. */'\n",
+"i=i+1;f(i)='#include <sys/stat.h> /* for S_IRUSR , S_IWUSR , S_IRGRP etc. */'\n",
+"i=i+1;f(i)='#define BUFSIZE 1024 /* May not be the rigth size here */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' int fd1, fd2; /* File descriptors for read and write */'\n",
+"i=i+1;f(i)=' int n; /* Number of characters returned by read */'\n",
+"i=i+1;f(i)=' char buf[BUFSIZE]; /* BUFSIZE should be carefully chosen */'\n",
+"i=i+1;f(i)=' fd1 = open('+ascii(34)+'/etc/passwd'+ascii(34)+',O_RDONLY);'\n",
+"i=i+1;f(i)=' fd2 = open('+ascii(34)+'passwd.bak'+ascii(34)+',O_WRONLY | O_CREAT | O_TRUNC ,'\n",
+"i=i+1;f(i)=' S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); /* Mode 664*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' while ((n = read(fd1, buf, BUFSIZE)) > 0) /* Return value of read is */'\n",
+"i=i+1;f(i)=' write(fd2, buf, n); /* used by write as argument */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' close(fd1);'\n",
+"i=i+1;f(i)=' close(fd2);'\n",
+"i=i+1;f(i)=' exit(0); /* This would have closed all file descriptors */'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat ccp.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('ccp.c','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",
+"halt(' ')\n",
+" printf('$ cc ccp.c')\n",
+" halt(' ')\n",
+" printf('$ a.out')\n",
+" halt(' ')\n",
+" printf('$ cmp /etc/passwd passwd.bak')\n",
+" halt(' ')\n",
+"if getos()=='Linux' then\n",
+"unix_w('cc ccp.c;a.out;cmp /etc/passwd passwd.bak')\n",
+"else\n",
+" printf('$ _ # Prompt returns-files identical')\n",
+" halt(' ')\n",
+"end\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 reversing a file using lseek \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: reverse_read.c -- Reads a file in reverse - uses lseek */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <fcntl.h> /* For O_RONLY */'\n",
+"i=i+1;f(i)='#include <unistd.h> /* For STDOUT_FILENO */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, char **argv) {'\n",
+"i=i+1;f(i)=' char buf; /* Single-character buffer; will make */'\n",
+"i=i+1;f(i)=' int size, fd; /* I/O inefficient. See Section 23.4 */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' fd= open(argv[1], O_RDONLY);'\n",
+"i=i+1;f(i)=' size = lseek(fd, -1, SEEK_END); /* Pointer taken to EOF - 1 ... */'\n",
+"i=i+1;f(i)=' while (size-- >= 0) { /* ... so siz = file size - 1 */'\n",
+"i=i+1;f(i)=' read(fd, &buf, 1); /* Read one character at a time */'\n",
+"i=i+1;f(i)=' write(STD_FILENO, &buf, 1); /* and write it immediately */'\n",
+"i=i+1;f(i)=' lseek(fd, -2, SEEK_CUR); /* Now move the file pointer back */'\n",
+"i=i+1;f(i)=' } /* by two characters */'\n",
+"i=i+1;f(i)=' /* exit(0); */ /* done deliberately */'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat reverse_read.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('reverse_read.c','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",
+"printf('\n$ ls \n')\n",
+"halt(' ')\n",
+"mode(0)\n",
+"ls\n",
+"mode(-1)\n",
+"nam=input('# Please enter a file from the above list : ','s')\n",
+"printf('\n$ cat %s ',nam)\n",
+"halt(' ')\n",
+"v=mopen(nam,'rt')\n",
+"while ~meof(v)\n",
+" [n,a]=mfscanf(v,'%c');\n",
+" if meof(v) break\n",
+" end\n",
+" printf('%c',a)\n",
+"end\n",
+"mclose(v)\n",
+"halt('')\n",
+"printf('\n$ cc reverse_read.c')\n",
+"halt('')\n",
+"printf('$ a.out %s \n......a blank line... The terminating \\n of the last line',nam)\n",
+"halt('')\n",
+"v=mopen(nam,'rt')\n",
+"mseek(-1,v,'end')\n",
+"siz=mtell(v)\n",
+"siz=siz-1\n",
+"while siz~=-1\n",
+" [n,a]=mfscanf(v,'%c');\n",
+" printf('%c',a)\n",
+" mseek(siz,v)\n",
+" siz=siz-1\n",
+"end\n",
+"mseek(0,v)\n",
+" [n,a]=mfscanf(v,'%c');\n",
+" printf('%c',a)\n",
+"mclose(v)\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 effect of umask on permissions of a file \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: umask.c -- Changes umask twice and checks effect on permissions */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <fcntl.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' mode_t old_mode,new_mode;'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' old_mode = umask(0); /* No mask */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Previous umask value: %o\n'+ascii(34)+', old_mode);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' open('+ascii(34)+'foo1'+ascii(34)+',O_RDONLY | O_CREAT, 0777); /* Create file using new mask */'\n",
+"i=i+1;f(i)=' umask(old_mode); /* Revert to previous mask */'\n",
+"i=i+1;f(i)=' open('+ascii(34)+'foo2'+ascii(34)+',O_RDWR | O_CREAT, 0764); /* Create file using old mask */'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='} '\n",
+"n=i\n",
+"printf('\n\n$ cat umask.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('umask.c','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",
+"halt(' ')\n",
+" printf('$ cc umask.c')\n",
+" halt(' ')\n",
+" printf('$ a.out')\n",
+" halt(' ')\n",
+" printf('Previous umask value: 22')\n",
+" halt(' ')\n",
+" printf('$ ls -l foo?')\n",
+" halt(' ')\n",
+"disp('-rwxrwxrwx 1 sumit sumit 0 Dec 1 12:01 foo1')\n",
+"disp('-rwxr--r-- 1 sumit sumit 0 Dec 1 12:01 foo2')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 : Print all the error messages present in the system using strerror \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: show_errors.c --Uses strerror to print all error messages */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' int i;'\n",
+"i=i+1;f(i)=' extern int sys_nerr; /* Total number of error messages */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' for (i=0; i < sys_nerr; i++)'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'%d: %s\n'+ascii(34)+', i, strerror(i));'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Number of errors available: %d\n'+ascii(34)+', sys_nerr);'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat show_errors.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('show_errors.c','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",
+"halt('')\n",
+"disp('$ cc show_errors.c')\n",
+"halt('')\n",
+"disp('$ a.out')\n",
+"halt('')\n",
+"printf('0: Error 0\n1: Not owner\n2:No such file or directory\n3: No such process\n4: Interrupted system call\n5: I/O error\n13: Permission denied\n')\n",
+"halt('')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 : Print all the system call errors with perror \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: show_errno.c -- Displaying system call errors with perror */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <fcntl.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, char **argv) {'\n",
+"i=i+1;f(i)=' int fd;'\n",
+"i=i+1;f(i)=' char* filename = '+ascii(34)+'non_existent_file'+ascii(34)+'; /* This file must not exist */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' fd = open(filename, O_RDONLY); /* File descriptor assigned first */'\n",
+"i=i+1;f(i)=' if (fd == -1) /* and then checked */'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'no_existent_file'+ascii(34)+');'\n",
+"i=i+1;f(i)=' if ((fd = open('+ascii(34)+'/etc/shadow'+ascii(34)+',O_RDONLY)) == -1) /* bOTH COMBINED HERE */'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'shadow'+ascii(34)+');'\n",
+"i=i+1;f(i)=' if ((fd = open('+ascii(34)+'show_errno.c'+ascii(34)+',O_WRONLY | O_CREAT | O_EXCL, 0744)) == -1)'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'show_errno.c'+ascii(34)+');'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat show_errorno.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('show_errorno.c','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",
+"halt('')\n",
+"disp('$ cc show_errorno.c')\n",
+"halt('')\n",
+"disp('$ a.out')\n",
+"halt('')\n",
+"printf('non_existent_file: No such file or directory\nshadow: Permission denied\nshow_errno.c: File exists\n ')\n",
+"halt('')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 : Show the method of reversing a file using error handling alternatives \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: reverse_read2.c -- Reads a file in reverse - uses error handling */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <fcntl.h> /* For 0_RDONLY */'\n",
+"i=i+1;f(i)='#include <unistd.h> /* For STDOUT_FILENO */'\n",
+"i=i+1;f(i)='#include <errno.h> /* For ENOENT, errno, etc. */'\n",
+"i=i+1;f(i)='#include <stdio.h> /* For ENOENT, errno, etc. */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, chr **argv) {'\n",
+"i=i+1;f(i)=' int size, fd;'\n",
+"i=i+1;f(i)=' char buf; /* Single-character buffer */'\n",
+"i=i+1;f(i)=' char *mesg = '+ascii(34)+'Not enough arguments\n'+ascii(34)+' ;'\n",
+" i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (argc != 2) { /* Our own user-defined error message */'\n",
+"i=i+1;f(i)=' write(STDERR_FILENO, mesg, strlen(mesg)); /* Crude form of error*/'\n",
+"i=i+1;f(i)=' exit(1); /*handling using write*/'\n",
+"i=i+1;f(i)=' } /* Use fprintf instead*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if ((fd = open(argv[1],O_RDONLY)) == -1) {'\n",
+"i=i+1;f(i)=' if (errno == ENOENT) { /* Checking for specific error*/'\n",
+"i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'%s\n'+ascii(34)+',stderror(errno)); /*perror is better*/'\n",
+"i=i+1;f(i)=' exit(2);'\n",
+"i=i+1;f(i)=' } else {'\n",
+"i=i+1;f(i)=' perror(argv[1]); /* Using two library functions */'\n",
+"i=i+1;f(i)=' exit(3); /* perror and exit.often the */'\n",
+"i=i+1;f(i)=' } /* preferred way */'\n",
+"i=i+1;f(i)=' } '\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' lseek(fd, 1, SEEK_END); /* Pointer taken to EOF + 1 first */'\n",
+"i=i+1;f(i)=' while (lseek(fd, -2, SEEK_CUR) >=0) { /* and then back by two bytes */ '\n",
+"i=i+1;f(i)=' if (read(fd, &buf, 1) != 1) { /* A signal can create error here */'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'read'+ascii(34)+');'\n",
+"i=i+1;f(i)=' exit(4);'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' if (write(STDOUT_FILENO, &buf, 1) != 1) { /* Disk may run out of space */'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'write'+ascii(34)+');'\n",
+"i=i+1;f(i)=' exit(5);'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' close(fd); /*Can have error here too*/'\n",
+"i=i+1;f(i)=' exit(0); /* exit doesn'+ascii(39)+'t return - hence no error */'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat reverse_read2.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('reverse_read2.c','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",
+"printf('\n$ ls \n')\n",
+"halt(' ')\n",
+"mode(0)\n",
+"ls\n",
+"mode(-1)\n",
+"nam=input('# Please enter a file from the above list : ','s')\n",
+"printf('\n$ cat %s ',nam)\n",
+"halt(' ')\n",
+"v=mopen(nam,'rt')\n",
+"while ~meof(v)\n",
+" [n,a]=mfscanf(v,'%c');\n",
+" if meof(v) break\n",
+" end\n",
+" printf('%c',a)\n",
+"end\n",
+"mclose(v)\n",
+"halt('')\n",
+"printf('\n$ cc reverse_read2.c')\n",
+"halt('')\n",
+"printf('$ a.out %s \n......a blank line... The terminating \\n of the last line',nam)\n",
+"halt('')\n",
+"v=mopen(nam,'rt')\n",
+"mseek(-1,v,'end')\n",
+"siz=mtell(v)\n",
+"siz=siz-1\n",
+"while siz~=-1\n",
+" [n,a]=mfscanf(v,'%c');\n",
+" printf('%c',a)\n",
+" mseek(siz,v)\n",
+" siz=siz-1\n",
+"end\n",
+"mseek(0,v)\n",
+" [n,a]=mfscanf(v,'%c');\n",
+" printf('%c',a)\n",
+"mclose(v)\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 directory navigation with chdir and getcwd \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: dir.c -- Directory navigation with chdir and getcwd */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#define PATH_LENGTH 200'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *,int ); /* Prototyoe definition */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, char **argv) {'\n",
+"i=i+1;f(i)=' char olddir[PATH_LENGTH + 1]; /* Extra character for null */'\n",
+"i=i+1;f(i)=' char newdir[PATH_LENGTH + 1];'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (getcwd(olddir, PATH_LENGTH) == -1) /* Getting current directory */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'getcwd'+ascii(34)+', 1);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'pwd: %s\n'+ascii(34)+',olddir);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if ((chdir(argv[1]) == -1)) /* Changing to another directory */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'chdir'+ascii(34)+', 2);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'cd: %s\n'+ascii(34)+', argv[1]);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /* getting new directory */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'pwd: %s\n'+ascii(34)+',newdir);'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat dir.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('dir.c','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",
+"halt(' ')\n",
+" printf('$ cc dir.c')\n",
+" halt(' ')\n",
+" disp('# Please enter the name of the directory which you want to go as the command line argument')\n",
+" disp('')\n",
+"nam=input('$ a.out ','s')\n",
+" halt(' ')\n",
+" pwd\n",
+" back=ans\n",
+" printf('pwd: %s\n',back)\n",
+" printf('cd: %s\n',nam)\n",
+" printf('pwd: %s Change of directory inside program\n',nam)\n",
+" cd(nam)\n",
+" halt('')\n",
+" printf('$ pwd \n')\n",
+" cd(back)\n",
+" printf('%s ...is not available outside it\n',back)\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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",
+"printf('Example 8 : Show the method of using readdir to populate a dirent structure \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: lls.c -- Uses readdir to populate a dirent structure */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <dirent.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, int **argv) {'\n",
+"i=i+1;f(i)=' DIR *dir; /* Returned by opendir*/'\n",
+"i=i+1;f(i)=' struct dirent *direntry; /* Returned by readdir*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if ((dir = opendir(argv[1])) == NULL) /* Directory must exist and*/'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'opendir'+ascii(34)+', 1); /* have read permission*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' while ((direntry = readdir(dir)) != NULL) /* Till there are new entries*/'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'%10d %s\n'+ascii(34)+',direntry->d_ino,direntry->d_name);'\n",
+"i=i+1;f(i)=' closedir(dir);'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='} '\n",
+" n=i\n",
+"printf('\n\n$ cat lls.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('lls.c','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",
+"halt(' ')\n",
+" printf('$ cc dir.c')\n",
+" halt(' ')\n",
+" disp('# Please enter the name of the directory which you want to go as the command line argument')\n",
+" disp('')\n",
+"nam=input('$ a.out ','s')\n",
+" halt(' ')\n",
+" pwd\n",
+" back=ans\n",
+" cd(nam)\n",
+"x=dir()\n",
+"dt=getdate(x.date);\n",
+"mprintf('%-20s : %05d-%03d-%03d %02d:%02d:%02d\n',x.name,dt(:,[1 2 6 7:9]))\n",
+" halt('')\n",
+" cd(back)\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 23.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 method of using lstatcall and struct stat to display file attributes\n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED')\n",
+"halt('')\n",
+"disp('3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook with no interactive input as in the programme below')\n",
+"halt('')\n",
+"disp('4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"disp('5.The inconvenience is regretted.')\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)='/* Program: attributes.c -- Uses lstat call and struct stat to display file attributes */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <sys/stath>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *,int);'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, char**argv) {'\n",
+"i=i+1;f(i)=' struct stat statbuf; /*We'+ascii(39)+'ll use lstat to populate this*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (lstat(argv[1], &statbuf) == -1)'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'Couldn'+ascii(39)+'t stat file'+ascii(34)+', 1);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'File: %s\n'+ascii(34)+',argv[1]);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Inode number: %d \n'+ascii(34)+',statbuf.st_ino);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'UID: %d '+ascii(34)+',statbuf.st_uid);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'GID: %d \n'+ascii(34)+',statbuf.st_gid);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Types and Permissions: %o\n'+ascii(34)+',statbuf.st_mode);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Number of links: %d \n'+ascii(34)+',statbuf.st_nlink);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Size in bytes: %d\n'+ascii(34)+',statbuf.st_size);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Blocks allocated: %d\n'+ascii(34)+',statbuf.st_blocks);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Last Modification Time: %s\n'+ascii(34)+',ctime(&statbuf.st_mtime));'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Last Access Time: %s\n'+ascii(34)+',ctime(&statbuf.st_atime));'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i \n",
+"printf('\n\n$ cat attributes.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('attributes.c','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",
+"halt(' ')\n",
+" printf('$ cc dir.c')\n",
+" halt(' ')\n",
+" disp('')\n",
+"printf('\nHere it displays a mock value since it is windows\n\n')\n",
+"if getos()=='Windows' then\n",
+" printf('\n$ a.out /etc/passwd\nFile: /etc/passwd\nInode number: 54412\nUID: 0 GID: 3\nType and Permissions: 100755\nNumber of links: 1')\n",
+"printf('\nSize in bytes: 10803\nBlocks allocated: 22\nLast Modification Time: Tue Nov 19 16:29:13 2002\nLast Access Time: Tue NOv 26 19:57:01 2002\n')\n",
+"else\n",
+" printf('$ a.out /etc/passwd')\n",
+" unix_w('cc attributes.c;a.out /etc/passwd')\n",
+"end\n",
+"halt(' ')\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)"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/24-Systems_Programming_2_Process_Control.ipynb b/Unix_Concepts_And_Applications_by_S_Das/24-Systems_Programming_2_Process_Control.ipynb
new file mode 100644
index 0000000..fce672b
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/24-Systems_Programming_2_Process_Control.ipynb
@@ -0,0 +1,1509 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 24: Systems Programming 2 Process Control"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 effect of using dup command to achieve both input and output redirection\n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: dup.c -- Uses dup to achieve both input and output redirection Closes standard streams first before using dup */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)='#include <sys/stat.h>'\n",
+"i=i+1;f(i)='#include <fcntl.h>'\n",
+"i=i+1;f(i)='#define MODE600 (S_IRUSR | S_IWUSR)'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc,char **argv) {'\n",
+"i=i+1;f(i)=' int fd1,int fd2;'\n",
+"i=i+1;f(i)=' fd1 = open(argv[1],O_RDONLY);'\n",
+"i=i+1;f(i)=' fd2 = open(argv[2], O_WRONLY | O_CREAT |O_TRUNC, MODE600);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' close(STDIN_FILENO); /*This should return descriptor 0 */'\n",
+"i=i+1;f(i)=' dup(fd1);'\n",
+"i=i+1;f(i)=' close(STDOUT_FILENO); /*This should return descriptor 1 */'\n",
+"i=i+1;f(i)=' dup(fd2);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' execvp(argv[3], &argv[3]); /* Execute any filter */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Failed to exec filter'+ascii(34)+');'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat dup.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('dup.c','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",
+"halt(' ')\n",
+" printf('$ cc shell.c')\n",
+" halt(' ')\n",
+" printf('$ a.out /etc/passwd passwd.cnt wc -1')\n",
+" halt(' ')\n",
+" printf('cat passwd.cnt')\n",
+"halt(' ')\n",
+"printf(' 37 /etc/passwd')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 effect of opening files int the parent and the child to reassign descriptors \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: dup2.c -- Opens files in the parent and uses dup2 in the child to reassign the descriptors */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)='#include <sys/stat.h>'\n",
+"i=i+1;f(i)='#include <fcntl.h>'\n",
+"i=i+1;f(i)='#include <wait.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#define OPENFLAGS (O_WRONLY | O_CREAT | O_TRUNC)'\n",
+"i=i+1;f(i)='#define MODE600 (S_IRUSR | S_IWUSR)'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *message, int exit_status) ;'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc,char **argv) {'\n",
+"i=i+1;f(i)=' int fd1, fd2, rv, exit_status;'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (fork() == 0) { /* Child */'\n",
+"i=i+1;f(i)=' if ((fd1 = pen(argv[1], O_RDONLY)) == -1)'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'Error in opening file for reading\n'+ascii(34)+', 1);'\n",
+"i=i+1;f(i)=' if ((fd2 = open(argv[2], OPENFLAGS, MODE600) == -1)'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'Error in opening file for writing\n'+ascii(34)+',1);'\n",
+"i=i+1;f(i)=' dup(fd1,0); /* Closes standard input simultaneously */'\n",
+"i=i+1;f(i)=' dup(fd2,1); /* Closes standard output simultaneously*/'\n",
+"i=i+1;f(i)=' execvp(argv[3], &argv[3]); /* Execute command */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'exec error'+ascii(34)+', 2);'\n",
+"i=i+1;f(i)='} else { /*parent */'\n",
+"i=i+1;f(i)='wait(&rv); /* Or use waitpid(-1,&rv, 0) */'\n",
+"i=i+1;f(i)='printf('+ascii(34)+'Exit status: %d\n'+ascii(34)+',WEXITSTATUS(rv));'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)='}'\n",
+"n=i \n",
+" \n",
+"printf('\n\n$ cat dup2.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('dup2.c','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",
+"halt(' ')\n",
+" printf('$ cc shell.c')\n",
+" halt(' ')\n",
+" printf('$ a.out /etc/passwd passwd.cnt grep joker')\n",
+" halt(' ')\n",
+" printf('Exit status: 1 # joker not found in /etc/passwd')\n",
+" halt('a.out /etc/passwd passwd.cnt grep sumit')\n",
+"printf('Exit status: 0 # sumit found in /etc/passwd ') \n",
+"halt(' ')\n",
+"printf('$ cat passwd.cnt')\n",
+"halt(' ')\n",
+"printf('sumit:x:500:500:sumitabha das:/home/sumit:/bin/bash')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 effect of sharing a pipe between two processes from parent to child \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: pipe.c -- Shares a pipe between two processes for data to flow from parent to child*/'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *, int);'\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' int n,fd[2]; /* fd[2] to be filled up by pipe() */'\n",
+"i=i+1;f(i)=' char buf[100]; /* Buffer to be used by read() */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (pipe(fd) < 0) /* fd[0] is read end */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'pipe'+ascii(34)+',1); /* fd[1] is write end */'\n",
+" i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' switch (fork()) { /* Pipe has four descriptors now */'\n",
+"i=i+1;f(i)=' case -1:quit('+ascii(34)+'Fork error'+ascii(34)+',2);'\n",
+"i=i+1;f(i)=' case 0:close(fd[1]); /* CHILD-Close write end of pipe */'\n",
+"i=i+1;f(i)=' n=read(fd[0],buf,100); /* and read from its read end */'\n",
+"i=i+1;f(i)=' write(STDOUT_FILENO,buf,n);'\n",
+"i=i+1;f(i)=' break;'\n",
+"i=i+1;f(i)=' default: close(fd[0]); /*PARENT-Close read end of pipe */'\n",
+"i=i+1;f(i)=' write(fd[1],'+ascii(34)+'Writing to pipe\n'+ascii(34)+', 16); /* write to write end */'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat pipe.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('pipe.c','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",
+"halt(' ')\n",
+" printf('$ cc shell.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ')\n",
+" halt(' ')\n",
+" printf('Writing to pipe')\n",
+" \n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.13: Program_13.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 13 : Show the method of running two programs in a pileline \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program pipe2.c -- Runs two programs in a pipeline Child runs cat, parent runs tr */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *message,int exit_status);'\n",
+"i=i+1;f(i)='int main(void) { '\n",
+"i=i+1;f(i)=' int fd[2]; /* To be fille dup by pipe() */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if (pipe(fd) < 0) /* Now have four descriptors for pipe */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'pipe'+ascii(34)+', 1);'\n",
+"i=i+1;f(i)=' switch (fork()) {'\n",
+"i=i+1;f(i)=' case -1: quit('+ascii(34)+'fork'+ascii(34)+', 2);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' case 0: close(fd[0]); /* CHILD - Close read end first */'\n",
+"i=i+1;f(i)=' dup2(fd[1], STDOUT_FILENO); /* Connect stdout to write end */'\n",
+"i=i+1;f(i)=' close(fd[1]); /* and close original descriptor */'\n",
+" i=i+1;f(i)=' execlp('+ascii(34)+'cat'+ascii(34)+', '+ascii(34)+'cat'+ascii(34)+','+ascii(34)+'/etc/hosts.equiv'+ascii(34)+', (char *) 0);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' default: close(fd[1]); /* PARENT -- Close write end first */'\n",
+"i=i+1;f(i)=' dup2(fd[0], STDIN_FILENO); /* Connect stdin to read end */'\n",
+"i=i+1;f(i)=' close(fd[0]); /* and close original descriptor */'\n",
+"i=i+1;f(i)=' execlp('+ascii(34)+'tr'+ascii(34)+', '+ascii(34)+'tr'+ascii(34)+', '+ascii(34)+''+ascii(39)+'[a-z]'+ascii(39)+''+ascii(34)+','+ascii(34)+''+ascii(39)+'[A-Z]'+ascii(39)+''+ascii(34)+',(char *) 0);'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'tr'+ascii(34)+', 4);'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat pipe2.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('pipe2.c','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",
+"halt(' ')\n",
+" printf('$ cc shell.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ')\n",
+" halt(' ')\n",
+" printf('SATURN\nEARTH\nMERCURY\nJUPITER\n')\n",
+" \n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.14: 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 14 : Show the use of generating signals and how the system can be made to catch it \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: signal.c -- Waits for 5 seconds for user input and then generates SIGALRM that has a handler specified */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)='#include <signal.h>'\n",
+"i=i+1;f(i)='#define BUFSIZE 100'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void alrm_handler(int signo); /* Prototypes declarations for */'\n",
+"i=i+1;f(i)='void quit(char *message,int exit_status); /*signal handler and quit */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='char buf[BUFSIZE] = '+ascii(34)+'foo\0'+ascii(34)+'; /* Global variable */'\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' int n;'\n",
+"i=i+1;f(i)=' if (signal(SIGALRM, alrm_handler) == SIG_ERR) /* signal returns SIG_ERR */'\n",
+"i=i+1;f(i)=' quit('+ascii(34)+'sigalrm'+ascii(34)+',1); /*on error*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'Enter filename: '+ascii(34)+');'\n",
+"i=i+1;f(i)=' alarm(5); /* Sets alarm clock;will deliver */'\n",
+"i=i+1;f(i)=' n = read(STDIN_FILENO, buf, BUFSIZE); /* SIGALRM in 5 seconds */'\n",
+"i=i+1;f(i)=' if (n>1) /* Will come here if user inputs */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Filename: %s\n'+ascii(34)+',buf); /* string within 5 seconds */'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void alrm_handler(int signo) { /* Invoked with process recieves SIGALRM */'\n",
+"i=i+1;f(i)=' signal(SIGALRM, alrm_handler); /* Resetting signal handler */'\n",
+"i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'\nSignal %d reeived, default filename: %s\n'+ascii(34)+', signo, buf);'\n",
+"i=i+1;f(i)=' exit(1);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat signal.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('signal.c','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",
+"halt(' ')\n",
+" printf('$ cc signal.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ')\n",
+" halt(' ')\n",
+"printf('Enter filename: ')\n",
+"sleep(1000);printf('s');sleep(300);printf('i');sleep(300);printf('g') ;sleep(300);printf('n') ;sleep(300);printf('a') ;sleep(300);printf('l') ;sleep(300);printf('.') ;sleep(300);printf('l') ;sleep(300);printf('o') ;sleep(300);printf('g') ;sleep(500) ;printf(' [-ENTER-]')\n",
+"printf('\nFilename: signal.log')\n",
+"halt('')\n",
+"printf('$ a.out')\n",
+"halt(' ')\n",
+"printf('Enter filename: # Do not enter anything')\n",
+"sleep(5000)\n",
+"printf('# Nothing entered in 5 seconds \n')\n",
+"printf('Signal 14 received, default filename: foo')\n",
+"halt(' ')\n",
+"printf('$ kill -l | grep 14 # What is signal 14')\n",
+"halt(' ')\n",
+"printf('13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGUSRI\n')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.15: Program_15.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 15 : Show the effect of [Ctrl-c] in the shell so as to do some operations \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: signal2.c -- Handles SIGINT and SIGTSTP generated from terminal Required two [Ctrl-c]s to terminate */'+ascii(39)+''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)='#include <signal.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void quit(char *message, int exit_status) ;'\n",
+"i=i+1;f(i)='void tstp_handler(int signo); /* Handler for [Ctrl-z] */'\n",
+"i=i+1;f(i)='void int_handler(int signo); /* Handler for [Ctrl-c] */'\n",
+"i=i+1;f(i)='int n, count=0;'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' signal(SIGTSTP, tstp_handler); /* Disposition for these two signals */'\n",
+"i=i+1;f(i)=' signal(SIGINT, int_handler); /* set to enter respective handler */'\n",
+"i=i+1;f(i)=' signal(SIGQUIT, SIG_IGN); /* Disposition set to ignore */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' fprintf(stderr,'+ascii(34)+'Press [Ctrl-z] first, then [Ctrl-c]\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' for(;;)'\n",
+"i=i+1;f(i)=' pause(); /* Will return on reciept of help */'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void tstp_handler(int signo) {'\n",
+"i=i+1;f(i)=' signal(SIGTSTP, tstp_handler); /* Not entirely reliable */'\n",
+"i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'Can'+ascii(39)+'t stop this program\n'+ascii(34)+'); /* same signal can reset */'\n",
+"i=i+1;f(i)='} /* disposition to default */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='void int_handler(int signo) { /* Will terminate program */'\n",
+"i=i+1;f(i)=' signal(SIGINT, int_handler); /* on second invocation */'\n",
+"i=i+1;f(i)=' (++count == 1) ? printf('+ascii(34)+'Press again\n'+ascii(34)+') : quit('+ascii(34)+'Quitting'+ascii(34)+', 1);'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat signal2.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('signal2.c','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",
+"halt(' ')\n",
+" printf('$ cc signal2.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ')\n",
+" halt(' ')\n",
+"printf('Press [Ctrl-z] first, then [Ctrl-c]')\n",
+"halt('')\n",
+"printf('# [Ctrl - \\] pressed ')\n",
+"sleep(2500)\n",
+"printf(' Signal Ignored \n')\n",
+"printf('# [Ctrl - z] pressed \n')\n",
+"sleep(2500)\n",
+"printf('Cannot stop this program From tstp_handler\n')\n",
+"printf('# [Ctrl - c] pressed ')\n",
+"sleep(2500)\n",
+"printf('\nPress again From int_handler\n')\n",
+"printf('# [Ctrl - c] pressed \n')\n",
+"sleep(2500)\n",
+"printf('Quitting: Interrupted system call From int_handler')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.16: Program_16.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"//Program for example 1 chapter 1\n",
+"printf('Current date is %s \n \nWelcome to the Textbook Companionship Project 2013 \n',date())\n",
+"printf('+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n')\n",
+"disp('Book Title : UNIX CONCEPTS AND APPLICATIONS ')\n",
+"disp('Book Edition : 4')\n",
+"disp('Book Author : Sumitabha Das')\n",
+"printf('+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n')\n",
+"disp('Code Author : Pranav Bhat T')\n",
+"printf('+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n')\n",
+"disp('Chapter Number : 24')\n",
+"disp('Chapter Title : Systems programming II- Files')\n",
+"printf('+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n'\n",
+"printf('Example 16 : Show the method of using fork and exec to run a user-defined\n program and kill it in 5 seconds if not completed \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: killprocess.c -- Uses fork and exec to run a user-defined program and kills it if it doesnt complete in 5 seconds */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <sys/types.h>'\n",
+"i=i+1;f(i)='#include <sys/wait.h>'\n",
+"i=i+1;f(i)='#include <signal.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='pid_t pid;'\n",
+"i=i+1;f(i)='int main(int argc, char **argv) {'\n",
+"i=i+1;f(i)=' int i,status;'\n",
+"i=i+1;f(i)=' void death_handler(int signo); /* A common signal handler this time */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' signal(SIGCHLD, death_handler); /* death_handler is invoked when a */'\n",
+"i=i+1;f(i)=' signal(SIGALRM, death_handler); /* child dies or an alarm is recieved */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' switch (pid = fork()) {'\n",
+"i=i+1;f(i)=' case -1: printf('+ascii(34)+'Fork error\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' case 0: execvp(argv[1],&argv[1]); /* Execute command */'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'exec'+ascii(34)+');'\n",
+"i=i+1;f(i)=' break;'\n",
+"i=i+1;f(i)=' default: alarm(5); /* Will send SIGALRM after 5 seconds */'\n",
+"i=i+1;f(i)=' pause(); /* Will return when SIGCHILD signal is received */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Parent dies\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' void death_handler(int signo) { /* This common handler pics up the */'\n",
+"i=i+1;f(i)=' int status; /* exit status for normal termination */'\n",
+"i=i+1;f(i)=' signal(signo, death_handler); /* but sends the SIGTERM signal if */'\n",
+"i=i+1;f(i)=' switch(signo) { /* command doesnt complete in 5 seconds */'\n",
+"i=i+1;f(i)=' case SIGCHLD: waitpid(-1, &status, 0); /* Same as wait(&status); */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Child dies; exit status: %d\n'+ascii(34)+',WEXITSTATUS(status));'\n",
+"i=i+1;f(i)=' break;'\n",
+"i=i+1;f(i)=' case SIGALRM: if (kill(pid, SIGTERM) == 0)'\n",
+"i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'5 seconds over,child killed\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat killprocess.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('killprocess.c','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",
+"halt(' ')\n",
+" printf('$ cc killprocess.c')\n",
+" halt(' ')\n",
+" printf('$ a.out date')\n",
+" halt(' ')\n",
+" printf('Sat Jun 20 22:29:27 IST 2013\nChild dies: exit status: 0\nParent dies')\n",
+"halt(' ')\n",
+"printf('\n')\n",
+"printf('$ a.out find /home -name a.out -print') \n",
+"halt(' ')\n",
+"printf('/home /sumit/personal/project8/a.out\n/home/sumit/personal/books_code/glass_ables/12/a.out\n/home/sumit/personal/books_code/stevens_c/ch08/a.out')\n",
+"printf(' ..after 5 second time interval ...')\n",
+"sleep(5000)\n",
+"printf('\n5 seconds over, child killed\nParent dies\n')\n",
+"halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.1: Program_1.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 1 : Show the method of showing all the type of process IDs \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: process.c -- Lists process and user credentials The PID, PPID, real and effective UIDs and GIDs */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'PID : %4d,PPDI : %4d\n'+ascii(34)+',getpid(),getppid());'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'UID : %4d, GID : %4d\n'+ascii(34)+',getuid(),getgid());'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'EUID : %4d,EGID : %4d\n'+ascii(34)+',geteuid(),getegid());'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+"printf('\n\n$ cat process.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('process.c','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",
+"halt(' ')\n",
+" printf('$ cc process.c')\n",
+" halt(' ')\n",
+" printf('$ a.out')\n",
+" halt(' ')\n",
+" printf('PID : 1035, PPID: 1028\nUID : 102, GID: 10\nEUID: 102, EGID: 10\n')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 showing PID,PPID in both parent and child process \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: fork.c -- A simple fork Shows PID,PPID in both parent and child*/'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <sys/types.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' pid_t pid;'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Before forking\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' pid = fork(); /* Replicates current processes */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' if(pid >0) { /* In the parent process; make sure */'\n",
+"i=i+1;f(i)=' sleep(1); /* That the parent does not die before child */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- PID: %d PPID %d, CHILD PID: %d\n'+ascii(34)+',getpid(),getppid(),pid);}'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' else if (pid == 0) /* In the child process */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- PID: %d PPID: %d\n'+ascii(34)+',getpid(),getppid());'\n",
+"i=i+1;f(i)=' else { /* pid must be -1 here */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Fork error\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' exit(1);}'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Both process continue from here\n'+ascii(34)+'); /* In both processes */'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"n=i \n",
+"printf('\n\n$ cat fork.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('fork.c','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",
+"halt(' ')\n",
+" printf('$ cc fork.c')\n",
+" halt(' ')\n",
+" printf('$ a.out')\n",
+" halt(' ')\n",
+" printf('Before forking\nCHILD -- PID: 1556 PPID: 1555\nBoth processes continue from here # This statement runs in child\nPARENT -- PID: 1555 PPID: 1450,CHILD PID: 1556\nBoth processes continue from here ...as well as in parent\n')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 effect of changing the childs environment and check its effect in parent \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: childenv.c -- Changes child'+ascii(39)+'s environment and then checks the effect in parent*/'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <sys/types.h>'\n",
+"i=i+1;f(i)='#define PATH_LENGTH 30'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' pid_t pid;'\n",
+"i=i+1;f(i)=' int x = 100;'\n",
+"i=i+1;f(i)=' char newdir[PATH_LENGTH + 1]; /* Additional space required for \0*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /* Get current directory before fork */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'BEFORE FORK -- Current directory: %s\n'+ascii(34)+', newdir);'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' pid = fork ();'\n",
+"i=i+1;f(i)=' switch (pid) {'\n",
+"i=i+1;f(i)=' case -1:'\n",
+"i=i+1;f(i)=' perror('+ascii(34)+'fork'+ascii(34)+');'\n",
+"i=i+1;f(i)=' exit(1); /*for error*/'\n",
+"i=i+1;f(i)=' case 0: /*Child*/'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Inherited value of x: %d\n'+ascii(34)+', x);'\n",
+"i=i+1;f(i)=' x=200;'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Changed value of x: %d\n'+ascii(34)+', x);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Inherited value of PATH: %s\n'+ascii(34)+', getenv('+ascii(34)+'PATH'+ascii(34)+'));'\n",
+"i=i+1;f(i)=' setenv('+ascii(34)+'PATH'+ascii(34)+','+ascii(34)+'.'+ascii(34)+', 1); /* Change PATH here; use putenv('+ascii(34)+'PATH=.'+ascii(34)+') */'\n",
+"i=i+1;f(i)=' /* if setenv() not supported */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- New value of PATH: %s\n'+ascii(34)+', getenv('+ascii(34)+'PATH'+ascii(34)+'));'\n",
+"i=i+1;f(i)=' if (chdir('+ascii(34)+'/etc'+ascii(34)+') != -) { /* '+ascii(34)+'cd'+ascii(34)+' to /etc */'\n",
+"i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /* Do a '+ascii(34)+'pwd'+ascii(34)+' */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Current directory changed to: %s\n'+ascii(34)+',newdir);'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' break;'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)=' default:/* Parent */'\n",
+"i=i+1;f(i)=' sleep(2); /* Allow child to complete */'\n",
+"i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /*Getting new directory */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- Value of x after change by child: %d\n'+ascii(34)+',x);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- Current directory is still: %s\n'+ascii(34)+', newdir);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- Value of PATH is unchanged: %s\n'+ascii(34)+',getenv('+ascii(34)+'PATH'+ascii(34)+'));'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)='}'\n",
+"n=i \n",
+" \n",
+"printf('\n\n$ cat childenv.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('childenv.c','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",
+"halt(' ')\n",
+" printf('$ cc childenv.c')\n",
+" halt(' ')\n",
+" printf('$ a.out')\n",
+" halt(' ')\n",
+" printf('BEFORE FORK -- Current directory: /users1/home/staff/sumit')\n",
+" printf('\nCHILD -- Inherited value of x: 100')\n",
+" printf('\nCHILD -- Changed value of x:200')\n",
+" printf('\nCHILD -- Inherited value of PATH: /usr/bin::/usr/local/bin:/usr/ccs/bin')\n",
+" printf('\nCHILD -- New value of PATH: .')\n",
+" printf('\nCHILD -- Current directory changed to: /etc')\n",
+" printf('\nPARENT -- Value of x after change to child: 100')\n",
+" printf('\nPARENT -- Current directory is still: /users1/home/staff/sumit')\n",
+" printf('\nPARENT -- Value of PATH is unchanged: /usr/bin::/usr/local/bin::/usr/ccs/bin')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.4: Program_4.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"printf('Example 4 : Show the effect of obtaining child termination status by WEXITSTATUS \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: wait.c -- Uses wait to obtain child'+ascii(39)+'s termination status.The WEXITSTATUS macro fetches the exit status */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <fcntl.h>'\n",
+"i=i+1;f(i)='#include <sys/wait.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, char **argv) {'\n",
+"i=i+1;f(i)=' int fd,exitstatus;'\n",
+"i=i+1;f(i)=' int exitval = 10; /* Value to be returned by child */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' fd= open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);'\n",
+"i=i+1;f(i)=' write(fd, '+ascii(34)+'Original process writes\n'+ascii(34)+',24); /* First write */'\n",
+" i=i+1;f(i)=''\n",
+"i=i+1;f(i)=' switch(fork()) {'\n",
+"i=i+1;f(i)=' case 0:'\n",
+"i=i+1;f(i)=' write(fd,'+ascii(34)+'Child writes\n'+ascii(34)+',13); /* Second write */'\n",
+"i=i+1;f(i)=' close(fd); /*Closing here doesn'+ascii(39)+'t affect parent'+ascii(39)+'s copy */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD: Terminating with exit value %d\n'+ascii(34)+', exitval);'\n",
+"i=i+1;f(i)=' exit(exitval); /* Can also use_exit(exitval) */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' default:'\n",
+"i=i+1;f(i)=' wait(&exitstatus); /* Waits for child to die */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'PARENT: Child terminated with exit value %d\n'+ascii(34)+',WEXITSTATUS(exitstatus));'\n",
+"i=i+1;f(i)=' /*Extracting exit status */'\n",
+"i=i+1;f(i)=' write(fd, '+ascii(34)+'Parent writes\n'+ascii(34)+', 14); /* Third write */'\n",
+"i=i+1;f(i)=' exit(20); /* Value returned to shell; try echo $? */'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat wait.c # to open the file ')\n",
+"halt(' ')\n",
+"u=mopen('wait.c','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",
+"halt(' ')\n",
+" printf('$ cc wait.c')\n",
+" halt(' ')\n",
+" printf('$ a.out foo')\n",
+" halt(' ')\n",
+" printf('CHILD: Terminating with exit value 10\nPARENT: Child terminated with exit value 10\n')\n",
+" halt(' ')\n",
+" printf('$ cat foo ')\n",
+" halt(' ')\n",
+" printf('Original process writes\nChild writes\nParent writes\n')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 effect of creating an orphan by letting child sleep for 2 minutes where parent dies immediately \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: orphan.c -- Creates an orphan by letting child sleep for 2 minutes.'\n",
+"i=i+1;f(i)=' Parent doesn'+ascii(39)+'t call wait and dies immediately */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' int pid;'\n",
+"i=i+1;f(i)=' if ((pid = fork()) > 0) /* Parent */'\n",
+"i=i+1;f(i)=' exit(10); /* Parent exits without calling wait */'\n",
+"i=i+1;f(i)=' else if (pid == 0) { /* Child */'\n",
+"i=i+1;f(i)=' sleep(2); /* Lets parent die in this time frame */'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'CHILD: Adopted by init now, PPID: %d\n'+ascii(34)+',getppid());'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)='}'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat orphan.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('orphan.c','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",
+"halt(' ')\n",
+" printf('$ cc orphan.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ....no response for 2 seconds...')\n",
+" halt(' ')\n",
+" sleep(2000)\n",
+" printf('CHILD: Adopted by init now, PPID: 1')\n",
+" halt(' ')\n",
+" printf('$ echo $?')\n",
+" halt(' ')\n",
+" printf('10')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 : Show the effect of using the execl series \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: execl.c -- Uses execl to run wc */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='int main(void) {'\n",
+"i=i+1;f(i)=' execl('+ascii(34)+'/bin/wc'+ascii(34)+','+ascii(34)+'wc'+ascii(34)+','+ascii(34)+'-l'+ascii(34)+','+ascii(34)+'-c'+ascii(34)+','+ascii(34)+'/etc/passwd'+ascii(34)+',(char*) 0);'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'execl error\n'+ascii(34)+');'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat execl.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('execl.c','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",
+"halt(' ')\n",
+" printf('$ cc execl.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ')\n",
+" halt(' ')\n",
+" printf(' 166 9953 /etc/passwd')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 effect of using the execv series \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: execv.c -- Stuffs all command line arguments to an an array to be used with execv */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='int main(int argc, char **argv) {'\n",
+"i=i+1;f(i)=' char *cmdargs[] = { '+ascii(34)+'grep'+ascii(34)+', '+ascii(34)+'-i'+ascii(34)+', '+ascii(34)+'-n'+ascii(34)+', '+ascii(34)+'SUMIT'+ascii(34)+', '+ascii(34)+'/etc/passwd'+ascii(34)+', NULL };'\n",
+"i=i+1;f(i)=' execv('+ascii(34)+'/bin/grep'+ascii(34)+', cmdargc); /* Execute another program*/'\n",
+"i=i+1;f(i)=' printf('+ascii(34)+'execv error\n'+ascii(34)+');'\n",
+"i=i+1;f(i)='}'\n",
+"n=i;\n",
+" \n",
+"printf('\n\n$ cat execv.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('execv.c','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",
+"halt(' ')\n",
+" printf('$ cc execv.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ')\n",
+" halt(' ')\n",
+" printf('15:sumit:x:102:10::/users1/home/staff/sumit:/usr/bin/bash')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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",
+"printf('Example 8 : Show the effect of using the exec command to run a unix command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: exec_and_fork.c -- Uses fork, exec and wait to run a unix command */'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <wait.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc,char **argv) {'\n",
+"i=i+1;f(i)=' int returnval; /* Used by wait*/'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' switch(fork()) {'\n",
+"i=i+1;f(i)=' case 0: /* Run command in child */'\n",
+"i=i+1;f(i)=' if ((exec(argv[1], &argv[2]) < 0 )) {'\n",
+"i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'execl error\n'+ascii(34)+');'\n",
+"i=i+1;f(i)=' exit(200);'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)=' default: /* In the parent */'\n",
+"i=i+1;f(i)=' wait(&returnval); /* After the command has completed .. */'\n",
+"i=i+1;f(i)=' fprintf(stderr,'+ascii(34)+'Exit status: %d\n'+ascii(34)+',WEXITSTATUS(returnval));'\n",
+"i=i+1;f(i)=' exit(0);'\n",
+"i=i+1;f(i)=' }'\n",
+"i=i+1;f(i)='}'\n",
+"n=i\n",
+" \n",
+"printf('\n\n$ cat exec_and_fork.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('exec_and_fork.c','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",
+"halt(' ')\n",
+" printf('$ cc exec_and_fork.c')\n",
+" halt(' ')\n",
+" printf('$ a.out /bin/grep grep -i -n SUMIT /etc/passwd ')\n",
+" halt(' ')\n",
+" printf('15:sumit:x:102:10::/users1/home/staff/sumit:/usr/bin/bash\nExit status: 0')\n",
+" halt(' ')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 24.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 effect of creating a mock child shell which accepts and executes commands \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"halt(' ')\n",
+"disp('1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB')\n",
+"halt(' ')\n",
+"disp('2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler')\n",
+"halt(' ')\n",
+"disp('3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK')\n",
+"halt(' ')\n",
+"disp('4.The inconvenience is regretted.')\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)='/* Program: shell.c -- Accepts user input as a command to be executed. Users the strtok library function for parsing command line*/'\n",
+"i=i+1;f(i)='#include <stdio.h>'\n",
+"i=i+1;f(i)='#include <unistd.h>'\n",
+"i=i+1;f(i)='#include <string.h> /*for strtok*/'\n",
+"i=i+1;f(i)='#include <wait.h>'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='#define BUFSIZE 200 /*Maximum size for the command line */'\n",
+"i=i+1;f(i)='#define ARGVSIZE 40 /* Maximum number of arguments*/'\n",
+"i=i+1;f(i)='#define DELIM '+ascii(34)+'\n\t\r'+ascii(34)+' /* White-space delimiters for strtok */'\n",
+"i=i+1;f(i)=''\n",
+"i=i+1;f(i)='int main(int argc, char **argv) {'\n",
+"i=i+1;f(i)=' int i,n ;'\n",
+"i=i+1;f(i)=' char buf[BUFSIZE + 1]; /* Stores the entered command line */'\n",
+"i=i+1;f(i)=' char *clargs[ARGVSIZE]; /* Stores the arguments strings */'\n",
+"i=i+1;f(i)=' int returnval ; /* Used by wait */'\n",
+"i=i+1;f(i)=' for (;;) { /* Loop forever */'\n",
+"i=i+1;f(i)=' n = 1;'\n",
+"i=i+1;f(i)=' write(STDOUT_FILENO, '+ascii(34)+'Shell> '+ascii(34)+',7); /*Display a prompt */'\n",
+"i=i+1;f(i)=' read(STDIN_FILENO, buf, BUFSIZE); /* Read user input into buf */'\n",
+"i=i+1;f(i)=' if (!strcmp(buf, '+ascii(34)+'exit\n'+ascii(34)+'))'\n",
+"i=i+1;f(i)=' exit(0); /* Terminate if user enters exit */'\n",
+"i=i+1;f(i)=' /* Now parse buf to extract the */'\n",
+"i=i+1;f(i)=' clargs[0] = strtok(buf, DELIM); /* first word */'\n",
+"i=i+1;f(i)=' /* Continue parsing until ... */'\n",
+"i=i+1;f(i)=' while ((clargs[n] = strtok(NULL, DELIM) != NULL)'\n",
+"i=i+1;f(i)=' n++; /* ...all words are extracted */'\n",
+"i=i+1;f(i)=' '\n",
+"i=i+1;f(i)=' clargs[n] = NULL; /* Set last arguments pointer to NULL */'\n",
+"i=i+1;f(i)=' switch(fork()) {'\n",
+"i=i+1;f(i)=' case 0:'\n",
+"i=i+1;f(i)=' if ((execvp(clargs[0], &clargs[0])) < 0)'\n",
+"i=i+1;f(i)=' exit(200); /* We will check this value later */'\n",
+"i=i+1;f(i)=' default: /* Int the parent */'\n",
+"i=i+1;f(i)=' wait(&returnval); /*After the command has completed.. */' \n",
+"i=i+1;f(i)=' printf('+ascii(34)+'Exit status of command: %d\n'+ascii(34)+',WEXITSTATUS(returnval));'\n",
+"i=i+1;f(i)=' for (i=0; i<=n ;i++) /*...initialise both... */'\n",
+"i=i+1;f(i)=' clargs[i] = '+ascii(34)+'\0'+ascii(34)+'; /*the argument array ...*/'\n",
+"i=i+1;f(i)=' for (i=0; i<BUFSIZE+1; i++)'\n",
+"i=i+1;f(i)=' buf[i] = '+ascii(39)+'\0'+ascii(39)+'; /* ... and the buffer that stores command */'\n",
+"i=i+1;f(i)=' } /* line, so next command can work with */'\n",
+"i=i+1;f(i)=' } /* an initialized buffer and argument */'\n",
+"i=i+1;f(i)='} /* array */'\n",
+"i=i+1;f(i)=''\n",
+"n=i \n",
+" \n",
+"printf('\n\n$ cat shell.c # to open the file emp.lst')\n",
+"halt(' ')\n",
+"u=mopen('shell.c','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",
+"halt(' ')\n",
+" printf('$ cc shell.c')\n",
+" halt(' ')\n",
+" printf('$ a.out ')\n",
+" halt(' ')\n",
+" printf('Shell> ')\n",
+" sleep(1500)\n",
+" printf('grep joker /etc/passwd')\n",
+" halt(' ')\n",
+" printf('Exit status of command: 1 #grep returns 1 if pattern not found')\n",
+" halt(' ')\n",
+" printf('Shell> ')\n",
+" sleep(1500)\n",
+" printf('pwd #Is this the shell builtin? ')\n",
+"halt(' ')\n",
+"printf('/users1/home/staff/sumit\nExit status of command: 0')\n",
+" halt(' ')\n",
+" printf('Shell> ')\n",
+"sleep(1500)\n",
+"printf('ls -lu /usr/bin/pwd # Now check the access time of on-disk pwd')\n",
+"halt(' ')\n",
+"printf('-r-xr-xr-x 1 root bin 4360 May 29 01:33 /use/bin/pwd\nExit status of command: 0 # Disk file has just been accessed! ')\n",
+" halt(' ')\n",
+" printf('Shell> ')\n",
+"sleep(1500)\n",
+"printf('exit')\n",
+"halt('')\n",
+"printf('$_ # Back to parent shell') \n",
+"halt(' ')\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)"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/3-General_Purpose_Utilities.ipynb b/Unix_Concepts_And_Applications_by_S_Das/3-General_Purpose_Utilities.ipynb
new file mode 100644
index 0000000..c9412a1
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/3-General_Purpose_Utilities.ipynb
@@ -0,0 +1,380 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 3: General Purpose Utilities"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.10: Machine_Characteristics.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 10 chapter 3\n",
+"clear()\n",
+"clc\n",
+"disp('Example 8 : Display the current machine name ')\n",
+"disp('***************************************************************************')\n",
+"disp('Answer : ')\n",
+"printf('The current machine details are\n ')\n",
+"if (getos()=='Linux') then\n",
+" unix_w('uname ;uname -r')\n",
+"else\n",
+" printf('Operating System : %s\n Version : %s\n',getos(),getversion())\n",
+"end\n",
+"disp('***************************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.11: Terminal_Name.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 10 chapter 3\n",
+"clear()\n",
+"clc\n",
+"disp('Example 9 : Display the user terminal details')\n",
+"disp('***************************************************************************')\n",
+"disp('Answer : ')\n",
+"printf('The current terminal details are\n ')\n",
+"if (getos()=='Linux') then\n",
+" unix_w('tty')\n",
+"else\n",
+" printf('The username details are %s\nThe terminal file details are %s\n',home,SCI)\n",
+"end\n",
+"disp('***************************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.1: Calendar.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear()\n",
+"//clc()\n",
+"printf('Example 1 : Display the calendar of the current month and of a date \nentered by the user ')\n",
+"printf('\n**********************************************************\n')\n",
+"printf('Answer :\n\n\n')\n",
+"printf('The current date is %s whose calendar is ',date())\n",
+"ct=calendar()\n",
+"clc(19)\n",
+"disp(ct(1))\n",
+"disp(ct(2))\n",
+"disp(ct(3))\n",
+"printf('\n--------------------------------------------------------------------------------------\n')\n",
+"printf('Enter a date whose calendar is to be displayed \n')\n",
+"x=input('Enter in the format [dd,mm,yyyy],ALONG WITH THE PARENTHESIS ')\n",
+"ct=calendar(x(3),x(2))\n",
+"clc(21)\n",
+"disp(ct(1))\n",
+"disp(ct(2))\n",
+"disp(ct(3))\n",
+"printf('\n\nEntered Date is %d - %d - %d \n',x(1),x(2),x(3))\n",
+"printf('\n***********************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.2: Date_and_Time.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear()\n",
+"dt=getdate()\n",
+"//clc()\n",
+"disp('Example 2 : Write a code sequence to display the current date and time')\n",
+"printf('\n**********************************************************\n')\n",
+"disp('Answer : ')\n",
+"printf('\n')\n",
+"printf('The current date is %s and the current time is %d : %d : %d \nThe day is ',date(),dt(7),dt(8),dt(9))\n",
+"select dt(5) \n",
+" case 1 then\n",
+" printf('Sunday')\n",
+" case 2 then\n",
+" printf('Monday')\n",
+" case 3 then\n",
+" printf('Tuesday')\n",
+" case 4 then\n",
+" printf('Wednesday')\n",
+" case 5 then\n",
+" printf('Thursday')\n",
+" case 6 then\n",
+" printf('Friday')\n",
+" case 7 then\n",
+" printf('Saturday')\n",
+"end\n",
+"printf('.')\n",
+"printf('\n**********************************************************\n')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.3: Use_of_echo.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 3 chapter 3\n",
+"clear\n",
+"clc\n",
+"disp('Example 3:Display a message or the value of a variable using the command echo')\n",
+"disp('********************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('')\n",
+"halt('Continue ...?? ')\n",
+"if (getos()~='Linux') then\n",
+" x=input('Enter any value to be Displayed Again : ','s')\n",
+" clc(1)\n",
+" printf('The entered value is %s',x)\n",
+" printf('\nTo display a Message :\nEnter Filename ')\n",
+"else\n",
+" unix_w('echo Enter n;read n;echo $n is entered value')\n",
+" unix_w('echo Enter filename \c')\n",
+" \n",
+"end\n",
+"disp('**********************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.4: printf_usage.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 4 chapter 3\n",
+"clear\n",
+"clc\n",
+"disp('Example 4:Display a message or the value of a variable using the command printf')\n",
+"disp('********************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('')\n",
+"halt('Continue ...?? ')\n",
+"if (getos()~='Linux') then\n",
+" printf('\nTo display a Message :\nEnter Filename ')\n",
+" printf('\nTo Display the value of a Variable : \n My Current Shell is %s\n',getshell())\n",
+"else\n",
+" unix_w('echo No Filename entered\nMy current shell is $SHELL\n')\n",
+" \n",
+"end\n",
+"disp('**********************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.5: hexadecimal_printing.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 5 chapter 3\n",
+"clear\n",
+"clc\n",
+"disp('Example 3:Display the value of an input letter in its octal and hexadecimal equivalent')\n",
+"disp('********************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('')\n",
+"halt('Continue ...?? ')\n",
+" x=input('Enter any value to be Displayed in its hexadecimal and octal equivalent : ')\n",
+" clc(1)\n",
+" printf('The value %d is %o in octal and %x in hexadecimal',x,x,x)\n",
+"disp('**********************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.6: Calculator.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 6 chapter 3\n",
+"clear\n",
+"t='y'\n",
+"clc\n",
+" disp('Example 6: Simulate a calculator to evaluate mathematical expressions')\n",
+" disp('*****************************************************************')\n",
+" disp('Answer : ')\n",
+" disp('Continue...??? ')\n",
+" printf('Enter the expressions to be evaluated one by one\n')\n",
+" halt('')\n",
+" //clc()\n",
+" printf('Calculator simulation using bc command in Unix\n\n')\n",
+" while t=='y'\n",
+" xt=input('Expression :: ','string')\n",
+" if xt=='^c' then\n",
+" break\n",
+" end\n",
+" printf('\n%d \n\n',evstr(xt))\n",
+" end\n",
+" //clc()\n",
+" printf('______ \n')\n",
+" printf(' | | | /\\ |\\ | | / | |\n')\n",
+" sleep(300)\n",
+" printf(' | |----| /--\\ | \\ | |< | |\n')\n",
+" sleep(300)\n",
+" printf(' | | | / \\ | \\| | \\ [___]\n') \n",
+" sleep(300)\n",
+" disp('Thank You') \n",
+" disp('*****************************************************************')"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 3.7: Session_recording_by_script.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"//Program for example 6 chapter 3\n",
+"clear\n",
+"t='n'\n",
+"clc\n",
+" disp('Example 7: Record the current session in a file and open the same')\n",
+" disp('*****************************************************************')\n",
+" disp('Answer : ')\n",
+" disp('Continue...??? ')\n",
+" halt('')\n",
+" \n",
+" printf('Enter the sequence of instructions to be recorded the session\nEnter yes to end the session and view result\n')\n",
+" halt('Press Enter to continue')\n",
+"mclose('Sessiont.txt')\n",
+" diary('Sessiont.txt','new')\n",
+" while t~='yes'\n",
+" //clc()\n",
+" xt=input('','string')\n",
+" if(xt=='yes') then\n",
+" t=xt\n",
+" clc(1)\n",
+" end\n",
+" \n",
+" clc(1)\n",
+"if(execstr(xt,'errcatch')==0) then\n",
+" v=evstr(xt)\n",
+" clc(1)\n",
+" disp(v(1))\n",
+" elseif(xt~=t) then\n",
+" disp('Wrong Command or Variable')\n",
+" else\n",
+" disp('') \n",
+" end\n",
+" halt('')\n",
+"end\n",
+"diary('Sessiont.txt','close')\n",
+"disp('Check for the file Sessiont.txt in the current directory...')\n",
+"halt('')\n",
+"disp('*****************************************************************')"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/4-The_File_System.ipynb b/Unix_Concepts_And_Applications_by_S_Das/4-The_File_System.ipynb
new file mode 100644
index 0000000..efd030e
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/4-The_File_System.ipynb
@@ -0,0 +1,389 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 4: The File System"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.1: Displaying_the_home_directory.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"mode(-1)\n",
+"clear\n",
+"clc\n",
+"disp('Example 1 : Show the path of the home directory of the file system')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n\n$ echo $HOME #To get the value of the home directory\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"printf(' %s \n',home)\n",
+"halt('........# (hit [ENTER] for next instruction)')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.2: Current_working_Directory.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"mode(-1)\n",
+"clear\n",
+"pwd\n",
+"xt=ans\n",
+"clc\n",
+"disp('Example 1 : Show the path of the current working directory')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n\n$ pwd #To get the value of the home directory\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"printf(' %s \n',xt)\n",
+"halt('........# (hit [ENTER] for next instruction)')\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.3: Changing_Directory.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"pwd\n",
+"cwd=ans\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 3 : Show the use of cd by going to the home directory \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n\n$ pwd #To get the value of the current directory\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"printf(' %s \n',cwd)\n",
+"halt('........# (hit [ENTER] for next instruction)')\n",
+"printf('\n\n\n$ cd #To go to the home directory\n\n')\n",
+"halt('........# (hit [ENTER] for next instruction)')\n",
+"clc(1)\n",
+"printf('\n\n\n$ pwd \n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"cd\n",
+"xt=ans\n",
+"printf(' %s \n',xt)\n",
+"halt('........# (hit [ENTER] for next instruction)')\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",
+"cd(cwd)\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.4: Creating_Directories.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"rmdir('pis')\n",
+"pwd\n",
+"cwd=ans\n",
+"clc\n",
+"printf('Example 4 : Show the method of creating a directory named pis \n \t\tand surf to the same directory \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n\n$ mkdir pis #To make a directory named pis\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"mkdir('pis')\n",
+"printf('\n\n\n$ cd pis #To go to the current directory\n\n')\n",
+"halt('........# (hit [ENTER] for next instruction)')\n",
+"clc(1)\n",
+"cd 'pis'\n",
+"xt=ans\n",
+"printf('\n\n\n$ pwd \n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"printf(' %s \n',xt)\n",
+"halt('........# (hit [ENTER] for next instruction)')\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",
+"cd(cwd)\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.5: Removing_Directories.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"rmdir('pis')\n",
+"pwd\n",
+"cwd=ans\n",
+"clc\n",
+"printf('Example 5 : Show the method of removing a directory\n named pis(after creating a directory named pis) \n \t\tand surf to the same directory \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n\n$ mkdir pis #To make a directory named pis\n\n')\n",
+"halt('........# (hit [ENTER] )')\n",
+"clc(1)\n",
+"mkdir('pis')\n",
+"printf('\n\n\n$ cd pis;pwd #To go to the directory named pis and open it\n\n')\n",
+"halt('........# (hit [ENTER] )')\n",
+"clc(1)\n",
+"cd 'pis'\n",
+"xt=ans\n",
+"printf(' %s \n',xt)\n",
+"halt('........# (hit [ENTER] )')\n",
+"printf('\n\n\n$ cd .. #To go to the parent directory\n\n')\n",
+"halt('........# (hit [ENTER] )')\n",
+"clc(1)\n",
+"cd(cwd)\n",
+"xt=ans\n",
+"printf('\n\n\n$ pwd \n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"printf(' %s \n',xt)\n",
+"halt('........# (hit [ENTER] for next instruction)')\n",
+"printf('\n\n\n$ rmdir pis #To make a directory named pis \n\n')\n",
+"halt('........# (hit [ENTER] )')\n",
+"clc(1)\n",
+"rmdir pis\n",
+"printf('\n\n\n$ ls pis #To go to the current directory\n\n')\n",
+"halt('........# (hit [ENTER] )')\n",
+"clc(1)\n",
+"ls pis\n",
+"printf(' pis : No such file or directory \n ')\n",
+"printf('\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n')\n",
+"halt('........# (hit [ENTER] )')\n",
+"cd(cwd)\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.6: Relative_Pathnames.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"pwd\n",
+"cwd=ans\n",
+"t=tokens(cwd,'\')\n",
+"par=strcat(t(1:(size(t,'r')-1)),'\')\n",
+"clc\n",
+"printf('Example 6 : Show the use of relative pathname .. by going to the parent of the current directory \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n\n$ pwd #To get the value of the current directory\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"printf(' %s \n',cwd)\n",
+"halt('........# (hit [ENTER] for next instruction)')\n",
+"printf('\n\n\n$ cd .. #To go to the current directory\n\n')\n",
+"halt('........# (hit [ENTER] for next instruction)')\n",
+"clc(1)\n",
+"cd(par)\n",
+"printf('\n\n\n$ pwd \n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"clc(1)\n",
+"printf(' %s \n',par)\n",
+"halt('........# (hit [ENTER] for next instruction)')\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",
+"cd(cwd)\n",
+"//clc()\n",
+"printf('\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')\n",
+"sleep(1000)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 4.7: ls_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"mode(-1)\n",
+"clear\n",
+"clc\n",
+"disp('Example 7 : Show the use of the file command ls for long listing of files')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n\n$ ls #To get the files and directories present in the current directory\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"mode(0)\n",
+"ls\n",
+"mode(-1)\n",
+"printf('\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n')\n",
+"printf('\n\n$ ls -l #To get the files and directories present in the current directory\n\n')\n",
+"halt('........# (hit [ENTER] for result)')\n",
+"mode(0)\n",
+"powershell('ls')\n",
+"mode(-1)\n",
+"halt('........# (hit [ENTER] for next instruction)')\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)"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/5-Handling_Ordinary_Files.ipynb b/Unix_Concepts_And_Applications_by_S_Das/5-Handling_Ordinary_Files.ipynb
new file mode 100644
index 0000000..32a9cdf
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/5-Handling_Ordinary_Files.ipynb
@@ -0,0 +1,793 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 5: Handling Ordinary Files"
+ ]
+ },
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.1: cat_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"printf('Example 1 : Show the method of file handling using the cat command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n# Enter the name of the file which you want to access \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"printf('# This searches for a file named %s \n\n',nam)\n",
+"if ~isfile(nam) then\n",
+" flag=0\n",
+" printf('\n%s : file not found \n',nam)\n",
+" printf('# Create a new file named %s?\n # y : Yes \n # n : No \n',nam)\n",
+" resp=input('','s')\n",
+" if resp=='y' then\n",
+" flag=1\n",
+" printf('\n#***Enter the contents of the file %s*****\n# [Enter ^ in a newline to end and close the file]\n',nam)\n",
+" printf('\n\n$ cat > %s #to create a file named %s and fill its contents\n',nam,nam)\n",
+" fhdr=mopen(nam,'wt')\n",
+" i=1\n",
+" while %t\n",
+" cont=input(string(i)+'. ','s')\n",
+" if (cont=='^') then\n",
+" break\n",
+" end\n",
+" mfprintf(fhdr,'%s\n',cont)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" end\n",
+"end\n",
+"if flag==1 then\n",
+" i=1\n",
+" clc\n",
+" printf('\n ===========> %s <============\n\n\n',nam)\n",
+" fhdr=mopen(nam,'rt')\n",
+" while %t\n",
+" [n,a]=mfscanf(fhdr,'%c')\n",
+" if meof(fhdr) then\n",
+" break\n",
+" end\n",
+" printf('%c',a)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" printf('\n\n%d characters present in the file.\n[hit ENTER to continue]\n',i)\n",
+" halt('')\n",
+"else\n",
+" printf('\n\n# file %s is not found and not created also\n',nam)\n",
+"end\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.2: cp_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"flag=1\n",
+"pwd\n",
+"xt=ans\n",
+"flag=1\n",
+"clc\n",
+"\n",
+"printf('Example 2 : Show the method of copying files in unix using the cp command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"src=input('# Enter the name of the file[or directory] which you want to copy : ','s')\n",
+"if isdir(src) then\n",
+"destn=input('# Enter the name of the directory which you want to copy into : ','s')\n",
+"else\n",
+" destn=input('# Enter the name of the file[or directory] which you want to copy into : ','s')\n",
+"end\n",
+"\n",
+"flag=0\n",
+"printf('\n $ cp %s %s \t#copies file[or directory] contents of %s to %s\n',src,destn,src,destn)\n",
+"halt('')\n",
+"\n",
+"\n",
+"if isfile(destn)&isfile(src) then\n",
+" printf('cp : overwrite %s (yes/no)? ',destn)\n",
+" resp=input(' ','s')\n",
+" if resp=='y' then\n",
+" mdelete(destn)\n",
+" end\n",
+"end\n",
+"\n",
+"if isfile(src)|isdir(src) then\n",
+" flag=1\n",
+" [status,msg]=copyfile(src,destn)\n",
+"else\n",
+" printf('\n%s : file or directory not found \n',src)\n",
+" flag=0\n",
+"end\n",
+"\n",
+"if flag==1&isfile(destn) then\n",
+" i=1\n",
+" printf('\n $ cat %s \t#to display the copied file %s \n\n',destn,destn)\n",
+" printf('\n ===========> %s <============\n\n\n',destn)\n",
+" fhdr=mopen(destn,'rt')\n",
+" while %t\n",
+" [n,a]=mfscanf(fhdr,'%c')\n",
+" if meof(fhdr) then\n",
+" break\n",
+" end\n",
+" printf('%c',a)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" printf('\n\n%d characters present in the file.\n[hit ENTER to continue]\n',i)\n",
+" halt('')\n",
+" elseif isdir(destn)&flag==1 then\n",
+" cd(destn)\n",
+" mode(0)\n",
+" ls\n",
+" halt('Go back to previous directory ?? ')\n",
+" mode(-1)\n",
+" cd(xt)\n",
+"else\n",
+" printf('\n\n# file %s is not rewritten using copy command cp and not created also\n',destn)\n",
+"end\n",
+"\n",
+"\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.3: rm_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"mode(-1)\n",
+"clc\n",
+"\n",
+"\n",
+"printf('Example 3 : Show the method of removing files in unix using the rm command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"src=input('# Enter the name of the file which you want to delete : ','s')\n",
+"\n",
+"flag=0\n",
+"printf('\n $ rm %s \t#deletes file %s\n',src,src)\n",
+"halt('')\n",
+"\n",
+"\n",
+"if isfile(src) then\n",
+" printf('rm : remove %s (yes/no)? ? ',src)\n",
+" resp=input(' ','s')\n",
+" if resp=='y' then\n",
+" mdelete(src)\n",
+" flag=1\n",
+" end\n",
+" else\n",
+" printf('\n%s : file not found \n',src) \n",
+"end\n",
+"\n",
+"if flag then\n",
+" printf('\n $ cat %s # opening file %s to see if it exists \n',src,src)\n",
+" if ~isfile(src) then\n",
+" printf('\n%s : file not found \n ',src)\n",
+" else\n",
+" \n",
+" printf('\n ===========> %s <============\n\n\n',destn)\n",
+" fhdr=mopen(destn,'rt')\n",
+" while %t\n",
+" [n,a]=mfscanf(fhdr,'%c')\n",
+" if meof(fhdr) then\n",
+" break\n",
+" end\n",
+" printf('%c',a)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" printf('\n\n%d characters present in the file.\n[hit ENTER to continue]\n',i)\n",
+" halt('')\n",
+"\n",
+" end\n",
+"end\n",
+"\n",
+"\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.4: mv_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"mode(-1)\n",
+"flag=1\n",
+"pwd\n",
+"xt=ans\n",
+"clc\n",
+"\n",
+"printf('Example 4 : Show the method of renaming files in unix using the mv command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"src=input('# Enter the name of the file[or directory] which you want to rename : ','s')\n",
+"if isdir(src) then\n",
+"destn=input('# Enter the new name of the directory : ','s')\n",
+"else\n",
+" destn=input('# Enter the name of the file[or directory] which you want to move into : ','s')\n",
+"end\n",
+"\n",
+"flag=0\n",
+"printf('\n $ mv %s %s \t#copies file[or directory] contents of %s to %s\n',src,destn,src,destn)\n",
+"halt('')\n",
+"\n",
+"\n",
+"if isfile(destn)&isfile(src) then\n",
+" printf('mv : overwrite %s (yes/no)? ',destn)\n",
+" resp=input(' ','s')\n",
+" if resp=='y' then\n",
+" mdelete(destn)\n",
+" end\n",
+"end\n",
+"\n",
+"if isfile(src)|isdir(src) then\n",
+" flag=1\n",
+" [status,msg]=movefile(src,destn)\n",
+"else\n",
+" printf('\n%s : file or directory not found \n',src)\n",
+" flag=0\n",
+"end\n",
+"\n",
+"if flag==1&isfile(destn) then\n",
+" i=1\n",
+" printf('\n $ cat %s \t#to display the moved file %s \n\n',destn,destn)\n",
+" printf('\n ===========> %s <============\n\n\n',destn)\n",
+" fhdr=mopen(destn,'rt')\n",
+" while %t\n",
+" [n,a]=mfscanf(fhdr,'%c')\n",
+" if meof(fhdr) then\n",
+" break\n",
+" end\n",
+" printf('%c',a)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" printf('\n\n%d characters present in the file.\n[hit ENTER to continue]\n',i)\n",
+" halt('')\n",
+"elseif isdir(destn)&flag==1 then\n",
+" cd(destn)\n",
+" mode(0)\n",
+" ls\n",
+" halt('Go back to previous directory ?? ')\n",
+" mode(-1)\n",
+" cd(xt)\n",
+"else\n",
+" printf('\n # No changes done in the file \n')\n",
+"end\n",
+"\n",
+"\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.5: lp_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"mode(-1)\n",
+"clear\n",
+"flag=1\n",
+"clc\n",
+"printf('Example 5 : Show the method of file printing using the lp command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"printf('\n# Enter the name of the file which you want to print \n\n')\n",
+"nam=input('$ lp ','s')\n",
+"printf('# This sends the file named %s to printer and gets status\n\n',nam)\n",
+"if ~isfile(nam) then\n",
+" flag=0\n",
+" printf('\n%s : file not found \n',nam)\n",
+" printf('# Create a new file named %s?\n # y : Yes \n # n : No \n',nam)\n",
+" resp=input('','s')\n",
+" if resp=='y' then\n",
+" flag=1\n",
+" printf('\n#***Enter the contents of the file %s*****\n# [Enter ^ in a newline to end and close the file]\n',nam)\n",
+" printf('\n\n$ cat > %s #to create a file named %s and fill its contents\n',nam,nam)\n",
+" fhdr=mopen(nam,'wt')\n",
+" i=1\n",
+" while %t\n",
+" cont=input(string(i)+'. ','s')\n",
+" if (cont=='^') then\n",
+" break\n",
+" end\n",
+" mfprintf(fhdr,'%s\n',cont)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" end\n",
+"end\n",
+"if flag then\n",
+"s=toprint(nam)\n",
+"if s then\n",
+" printsetupbox()\n",
+"else\n",
+" printf('\n\nlp : printer busy \n')\n",
+"end\n",
+"end\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.6: wc_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"mode(-1)\n",
+"clear\n",
+"flag=1\n",
+"clc\n",
+"\n",
+"printf('Example 6 : Show the method of file counting using the wc command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"\n",
+"printf('\n# Enter the name of the file which you want to access \n\n')\n",
+"nam=input('$ cat ','s')\n",
+"printf('# This searches for a file named %s to display\n\n',nam)\n",
+"\n",
+"\n",
+"if ~isfile(nam) then\n",
+" flag=0\n",
+" printf('\n%s : file not found \n',nam)\n",
+" printf('# Create a new file named %s?\n # y : Yes \n # n : No \n',nam)\n",
+" resp=input('','s')\n",
+" if resp=='y' then\n",
+" flag=1\n",
+" printf('\n#***Enter the contents of the file %s*****\n# [Enter ^ in a newline to end and close the file]\n',nam)\n",
+" printf('\n\n$ cat > %s #to create a file named %s and fill its contents\n',nam,nam)\n",
+" fhdr=mopen(nam,'wt')\n",
+" i=1\n",
+" while %t\n",
+" cont=input(string(i)+'. ','s')\n",
+" if (cont=='^') then\n",
+" break\n",
+" end\n",
+" mfprintf(fhdr,'%s\n',cont)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" end\n",
+"end\n",
+"\n",
+"if flag==1 then\n",
+" c=1\n",
+" w=0\n",
+" l=0\n",
+" clc\n",
+" printf('\n $ cat %s \n',nam)\n",
+" fhdr=mopen(nam,'rt')\n",
+" while %t\n",
+" [n,a]=mfscanf(fhdr,'%c')\n",
+" if meof(fhdr) then\n",
+" break\n",
+" end\n",
+" \n",
+" printf('%c',a)\n",
+" c=c+1\n",
+" if ascii(a)==32 then\n",
+" w=w+1\n",
+" end\n",
+" if ascii(a)==10 then\n",
+" w=w+1\n",
+" l=l+1\n",
+" end\n",
+" end\n",
+" mclose(fhdr)\n",
+" halt('')\n",
+" printf('\n\n$ wc %s #to get the count in file named %s \n',nam,nam)\n",
+" halt('') \n",
+" printf('\t%d\t%d\t%d %s\n',l,w,c,nam)\n",
+" printf('\n# This means there are %d words,%d characters\n \t and %d lines in the file %s \n',w,c,l,nam)\n",
+" printf('\n\n$ wc -l %s #to get the line count in file named %s \n',nam,nam)\n",
+" halt('') \n",
+" printf('\t%d %s\n',l,nam)\n",
+" printf('\n# Number of lines \n')\n",
+" printf('\n\n$ wc -w %s #to get the word count in file named %s \n',nam,nam)\n",
+" halt('') \n",
+" printf('\t%d %s\n',w,nam)\n",
+" printf('\n# Number of words \n')\n",
+" printf('\n\n$ wc -c %s #to get the character count in file named %s \n',nam,nam)\n",
+" halt('') \n",
+" printf('\t%d %s\n',c,nam)\n",
+" printf('\n# Number of characters \n')\n",
+"end\n",
+"\n",
+"\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.7: od_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"clc\n",
+"mode(-1)\n",
+"\n",
+"printf('Example 7 : Show the method of file handling using the od command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"\n",
+"printf('\n# Enter the name of the file which you want to access \n\n')\n",
+"nam=input('$ od ','s')\n",
+"printf('# This searches for a file named %s \n\n',nam)\n",
+"\n",
+"\n",
+"if ~isfile(nam) then\n",
+" flag=0\n",
+" printf('\n%s : file not found \n',nam)\n",
+" printf('# Create a new file named %s?\n # y : Yes \n # n : No \n',nam)\n",
+" resp=input('','s')\n",
+" if resp=='y' then\n",
+" flag=1\n",
+" printf('\n#***Enter the contents of the file %s*****\n# [Enter ^ in a newline to end and close the file]\n',nam)\n",
+" printf('\n\n$ cat > %s #to create a file named %s and fill its contents\n',nam,nam)\n",
+" fhdr=mopen(nam,'wt')\n",
+" i=1\n",
+" while %t\n",
+" cont=input(string(i)+'. ','s')\n",
+" if (cont=='^') then\n",
+" break\n",
+" end\n",
+" mfprintf(fhdr,'%s\n',cont)\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" end\n",
+"end\n",
+"\n",
+"if flag==1 then\n",
+" i=1\n",
+" clc\n",
+" printf('\n $ od %s #to display %s in octal characters\n\n',nam,nam)\n",
+" printf('\n ===========> %s <============\n\n\n',nam)\n",
+" fhdr=mopen(nam,'rt')\n",
+" while %t\n",
+" [n,a]=mfscanf(fhdr,'%c')\n",
+" if meof(fhdr) then\n",
+" break\n",
+" end\n",
+" printf(' %o',ascii(a))\n",
+" if ascii(a)==10 then\n",
+" printf('\n')\n",
+" end\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" printf('\n\n%d characters present in the file.\n[hit ENTER to continue]\n',i)\n",
+" halt('')\n",
+"else\n",
+" printf('\n\n# file %s is not found and not created also\n',nam)\n",
+"end\n",
+"\n",
+"flag=flag+1\n",
+"\n",
+"octs=blanks(0)\n",
+"if flag==2 then\n",
+" i=1\n",
+" clc\n",
+" printf('\n $ od -bc %s #to display %s in octal characters\n\n',nam,nam)\n",
+" printf('\n ===========> %s <============\n\n\n',nam)\n",
+" fhdr=mopen(nam,'rt')\n",
+" while %t\n",
+" [n,a]=mfscanf(fhdr,'%c')\n",
+" if meof(fhdr) then\n",
+" break\n",
+" end\n",
+" printf(' %c ',a)\n",
+" octs=octs+string(dec2oct(ascii(a)))+' '\n",
+" if ascii(a)==10 then\n",
+" printf('%s\n\n',octs)\n",
+" clear('octs')\n",
+" octs=blanks(0)\n",
+" end\n",
+" i=i+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" printf('\n\n%d characters present in the file.\n[hit ENTER to continue]\n',i)\n",
+" halt('')\n",
+"else\n",
+" printf('\n\n# file %s is not found and not created also\n',nam)\n",
+"end\n",
+"\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)"
+ ]
+ }
+,
+{
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Example 5.8: cmp_command.sce"
+ ]
+ },
+ {
+"cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+"source": [
+"clear\n",
+"flag=1\n",
+"clc\n",
+"mode(-1)\n",
+"\n",
+"printf('Example 8 : Show the method of comparing files using cmp command \n')\n",
+"disp('****************************************************************')\n",
+"disp('Answer : ')\n",
+"disp('INSTRUCTIONS : ')\n",
+"printf('\nHere all instructions are preloaded in the form of a demo\nPRESS ENTER AFTER EACH COMMAND to see its RESULT\nPRESS 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",
+"\n",
+"printf('\n# Enter the name of the two files which you want to compare \n')\n",
+"fil(1)=input('','s')\n",
+"fil(2)=input('','s')\n",
+"printf('\n\n $ cmp %s %s #to compare the files %s and %s\n',fil(1),fil(2),fil(1),fil(2))\n",
+"\n",
+"for i=1:2\n",
+"if ~isfile(fil(i)) then\n",
+" flag(i)=0\n",
+" printf('\n%s : file not found \n',fil(i))\n",
+" printf('# Create a new file named %s?\n # y : Yes \n # n : No \n',fil(i))\n",
+" resp=input('','s')\n",
+" if resp=='y' then\n",
+" flag(i)=1\n",
+" printf('\n#***Enter the contents of the file %s*****\n# [Enter ^ in a newline to end and close the file]\n',fil(i))\n",
+" printf('\n\n$ cat > %s #to create a file named %s and fill its contents\n',fil(i),fil(i))\n",
+" fhdr=mopen(fil(i),'wt')\n",
+" count=1\n",
+" while %t\n",
+" cont=input(string(count)+'. ','s')\n",
+" if (cont=='^') then\n",
+" break\n",
+" end\n",
+" mfprintf(fhdr,'%s\n',cont)\n",
+" count=count+1\n",
+" end\n",
+" mclose(fhdr)\n",
+" end\n",
+"end\n",
+"end\n",
+"\n",
+"\n",
+"if flag(1)&flag(2) then\n",
+" clc\n",
+" printf('\n $ cmp %s %s #to compare files %s and %s \n',fil(1),fil(2),fil(1),fil(2))\n",
+" fhdr1=mopen(fil(1),'rt')\n",
+" fhdr2=mopen(fil(2),'rt')\n",
+" l=0\n",
+" cr=1\n",
+" while %t\n",
+" [n,a1]=mfscanf(fhdr1,'%c')\n",
+" [n,a2]=mfscanf(fhdr2,'%c')\n",
+" if meof(fhdr1)&meof(fhdr2) then\n",
+" printf(' \n# No output means both the files are identical \n')\n",
+" break\n",
+" elseif (meof(fhdr1)&~meof(fhdr2))|(meof(fhdr2)&~meof(fhdr1))|a1~=a2\n",
+" printf(' %s %s differ : char %d , line %d \n',fil(1),fil(2),cr,l+1)\n",
+" printf(' # This shows that %dth character in %dth line do not match\n\n',cr,l+1)\n",
+" break\n",
+" end\n",
+" cr=cr+1\n",
+" if ascii(a1)==10 then\n",
+" l=l+1\n",
+" cr=1\n",
+" end\n",
+" end\n",
+" mclose(fhdr1)\n",
+" mclose(fhdr2)\n",
+" halt('')\n",
+"else\n",
+" printf('\n\n# file %s or %s is not found \n',fil(1),fil(2))\n",
+"end\n",
+"\n",
+"\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)"
+ ]
+ }
+],
+"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
+}
diff --git a/Unix_Concepts_And_Applications_by_S_Das/7-Basic_File_Attributes.ipynb b/Unix_Concepts_And_Applications_by_S_Das/7-Basic_File_Attributes.ipynb
new file mode 100644
index 0000000..6437c99
--- /dev/null
+++ b/Unix_Concepts_And_Applications_by_S_Das/7-Basic_File_Attributes.ipynb
@@ -0,0 +1,32 @@
+{
+"cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Chapter 7: Basic File Attributes"
+ ]
+ },
+],
+"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
+}