Script started on Mon 11 Nov 2024 12:36:01 PM EST [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ echo 3243 3243 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat predefined.sh echo You passed $# parameters. echo These are: "$@" echo process ID of last background process = $! echo process ID of this shell = $$ notAcommand echo Last command returned with $? as the status.[mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./predefined.sh You passed 0 parameters. These are: process ID of last background process = process ID of this shell = 24837 ./predefined.sh: line 5: notAcommand: command not found Last command returned with 127 as the status. [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./predefined.sh one two three You passed 3 parameters. These are: one two three process ID of last background process = process ID of this shell = 24863 ./predefined.sh: line 5: notAcommand: command not found Last command returned with 127 as the status. [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ echo hello hello [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ echo status $? status 0 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ echo $HOME /home/mweeks [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./readme bash: ./readme: No such file or directory [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./readme.sh one two three four five six seven you said one two three then you said four five six seven [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat readme.sh #!/bin/bash # read multiple lines read v1 read v2 echo "you said $v1" echo "then you said $v2" [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat test_file_exists.sh if [ -e "$1" ]; then echo "The file exists." fi[mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./test_file_exists.sh readme.sh The file exists. [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./test_file_exists.sh nofile [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cp test_file_exists.sh test_file_exists2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ vi test_file_exists2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat test_file_exists2.sh if [ -e "$1" ]; then echo "The file exists." else echo "The file does not exist" fi [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ls -l test_file_exists* -rwxr-xr-x. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 89 Nov 11 12:49 test_file_exists2.sh -rwxr-xr-x. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 49 Nov 11 12:34 test_file_exists.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./test_file_exists2.sh onetwo The file does not exist [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat testif.sh echo "enter a word: " read v1 if [ -e $v1 ] then echo "A file by that name exists." else echo "No file by that name exists." fi [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testif.sh enter a word: onetwo No file by that name exists. [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testif.sh enter a word: readme.sh A file by that name exists. [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat testcase.sh echo "Type out the word for 1 or 2:" read v1 case $v1 in [Oo]ne) echo "You entered 1" ;; [Tt]wo) echo "You entered 2" ;; *) echo "sorry" ;; esac [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase.sh Type out the word for 1 or 2: one You entered 1 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase.sh Type out the word for 1 or 2: two You entered 2 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase.sh Type out the word for 1 or 2: Two You entered 2 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase.sh Type out the word for 1 or 2: three sorry [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase.sh Type out the word for 1 or 2: oNE sorry [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cp testcase.sh testcase2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ vi testcase2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase2.sh Type out the word for 1 or 2: oNe You entered 1 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase2.sh Type out the word for 1 or 2: Pne You entered 1 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat testcase2.sh echo "Type out the word for 1 or 2:" read v1 case $v1 in [OopP][nN]e) echo "You entered 1" ;; [Tt]wo) echo "You entered 2" ;; *) echo "sorry" ;; esac [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase2.sh one Type out the word for 1 or 2: one You entered 1 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cp testcase2.sh testcase3.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ vi testcase3.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase3.sh Type out the word for 1 or 2: pPne sorry [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat testcase3.sh echo "Type out the word for 1 or 2:" read v1 case $v1 in [Oo[pP]][nN]e) echo "You entered 1" ;; [Tt]wo) echo "You entered 2" ;; *) echo "sorry" ;; esac [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase3.sh Type out the word for 1 or 2: one sorry [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase3.sh Type out the word for 1 or 2: opne sorry [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ git bash: git: command not found [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat testfor.sh params=$@ for value in $params do echo param: $value done [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testfor.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testfor.sh one two three param: one param: two param: three [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ v3="three" [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ echo v3 $v3 v3 three [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ v4 = "four" bash: v4: command not found [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ echo $v4 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat testwhile.sh x=1 while [ $x -lt 4 ] do echo x = ${x}, less than four x=`expr $x + 1` done [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testwhile.sh x = 1, less than four x = 2, less than four x = 3, less than four [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat testuntil.sh x=1 until [ $x -gt 3 ] do echo x = $x x=`expr $x + 1` done [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testuntil.sh x = 1 x = 2 x = 3 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat simple.sh #!/bin/bash # #name="one" #${name=word} #echo $name if [ "$name" == "" ]; then name="word" fi echo $name [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./simple.sh word [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cp simple.sh multiargs.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ vi multiargs.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./multiargs.sh default_input.txt for input default_output.txt for output [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./multiargs.sh myinput.txt myinput.txt for input default_output.txt for output [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./multiargs.sh myinput.txt myoutput.csv myinput.txt for input myoutput.csv for output [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat multiargs.sh #!/bin/bash # # We expect the user to give us a pair of filenames, # an input file and an output file. file1=$1 file2=$2 if [ "$file1" == "" ]; then file1="default_input.txt" fi echo $file1 for input if [ "$file2" == "" ]; then file2="default_output.txt" fi echo $file2 for output [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cp multiargs.sh multiargs2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ vi multiargs2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./multiargs2.sh myinput.txt myoutput.csv myinput.txt for input myoutput.csv for output The input file does not exist. Exiting. [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ touch myinput.txt [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ls -l myinput.txt -rw-rw-r--. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 0 Nov 11 13:33 myinput.txt [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./multiargs2.sh myinput.txt myoutput.csv myinput.txt for input myoutput.csv for output The input file exists, which is good. The output file does not exist, which is good [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ touch myoutput.csv [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./multiargs2.sh myinput.txt myoutput.c myinput.txt for input myoutput.csv for output The input file exists, which is good. The output file exists, exiting [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ vi myinput.txt [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ls -l readme.* -rwxr-xr-x. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 96 Nov 11 12:34 readme.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ touch readme.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ls -l readme.* -rwxr-xr-x. 1 mweeks@gsuad.gsu.edu mweeks@gsuad.gsu.edu 96 Nov 11 13:35 readme.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cat multiargs2.sh #!/bin/bash # # We expect the user to give us a pair of filenames, # an input file and an output file. file1=$1 file2=$2 if [ "$file1" == "" ]; then file1="default_input.txt" fi echo $file1 for input if [ "$file2" == "" ]; then file2="default_output.txt" fi echo $file2 for output # Does file1 exist? if [ -e "$file1" ] then echo The input file exists, which is good. else echo The input file does not exist. Exiting. exit 1 fi # Does file2 exist? if [ -e "$file2" ] then echo The output file exists, exiting exit 1 else echo The output file does not exist, which is good fi [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ null bash: null: command not found [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ cp testcase.sh testcase2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ vi testcase2.sh [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ ./testcase2.sh Type out the word for 1 or 2: two ./testcase2.sh: line 8: null: command not found [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ expr 2 + 2 4 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ expr 2 + 2 = 4 1 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ expr 2 \* 3 6 [mweeks@gsuad.gsu.edu@snowball unix_ch5]$ exit exit Script done on Mon 11 Nov 2024 01:44:17 PM EST