-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_listing
934 lines (751 loc) · 21.6 KB
/
script_listing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
#!/bin/more
======================================
SCRIPT NAME: arithmetic_operators.sh
======================================
#!/bin/bash
# This script is intended to show the usage of
# arithmetic operations
# Addition
expr 2 + 2
# Subtration
expr 2 - 2
# Division
expr 2 / 2
# Multiplication - * must be escaped with \
expr 2 \* 2
# Modulus
expr 15 % 2
# Command substitution
echo `expr 15 \* 2`
# Set expression to variable
MY_VARIABLE=$(expr 10 \* 20)
echo $MY_VARIABLE
======================================
SCRIPT NAME: arrays.sh
======================================
#!/bin/bash
# This script intends to show the usage of arrays in bash
MYARRAY=("First" "Second" "Third")
# will only echo 0 index value of array
echo $MYARRAY
# Enclose variable in brackets with index position to echo
echo ${MYARRAY[0]}
echo ${MYARRAY[1]}
echo ${MYARRAY[2]}
# Echo all items in array
echo ${MYARRAY[*]}
MYARRAY[3]="Fourth"
echo ${MYARRAY[*]}
# Comma delimited arrays are bad - bash treats the array elements
# as a single array element
NEWARRAY=("First","Second","Third")
echo $NEWARRAY
echo ${NEWARRAY[0]}
# Simple array list and loop for display
SERVERLIST=("websrv01" "websrv02" "websrv03" "websrv04")
COUNT=0
for INDEX in ${SERVERLIST[@]}; do
echo "Processing Server: ${SERVERLIST[COUNT]}"
COUNT="$(expr $COUNT + 1)"
done
======================================
SCRIPT NAME: case_statement.sh
======================================
#!/bin/bash
# This script is intended to show the usage of a case statement
clear
echo " MAIN MENU"
echo "==============="
echo "1) Choice One"
echo "2) Choice Two"
echo "3) Choice Three"
echo ""
echo "Enter choice:"
read MENUCHOICE
case $MENUCHOICE in
1)
echo "You chose option #1";;
2)
echo "You chose option #2";;
3)
echo "You chose option #3";;
*)
echo "You chose poorly";;
esac
======================================
SCRIPT NAME: checkargs1.sh
======================================
#!/bin/bash
# This script is intended to show how to check CLI parameters
if [ "$#" != "3" ]; then
echo "USAGE: checkargs.sh [param1] [param2] [param3]"
exit 300
fi
echo "I live! I got what I needed"
======================================
SCRIPT NAME: checkargs2.sh
======================================
#!/bin/bash
# If statement on one line to check CLI arguments passed through
: ${3?"Usage: $1 ARGUMENT $2 ARGUMENT $3 ARGUMENT"}
echo "I got all three!"
======================================
SCRIPT NAME: cli_vars.sh
======================================
#!/bin/bash
# This script is intended to show how to pass arguments
# from the command-line to this script
USERNAME=$1
PASSWORD=$2
echo "The following username is $USERNAME and password is $PASSWORD"
======================================
SCRIPT NAME: cmd_substitution.sh
======================================
#!/bin/bash
# This script is intended to show how to do simple substitution
# Allows to expand aliases in subshells
shopt -s expand_aliases
alias TODAY="date"
alias UFILES="find /home -user david.coy"
TODAYDATE=`date`
USERFILES=`find /home -user david.coy` # Will not output anything on Darwin
echo "$TODAYDAY"
echo "$USERFILES"
A=`TODAY`
B=`UFILES`
echo "With alias, TODAY is:"
echo "With alias, UFILES is:"
======================================
SCRIPT NAME: comments.sh
======================================
#!/bin/bash
# This line is intended to be used as a general description
# of the script and anything it does
echo '####################################'
echo "This line above is not commented out" # This is commented out
======================================
SCRIPT NAME: dev_null_usage.sh
======================================
#!/bin/bash
# This script intends to show the usage
# of /dev/null
# Redirect to /dev/null
echo "This is displaying on the console."
echo "This is going into the black hole." >> /dev/null
# Redirect STDOUT to /dev/null
echo "This is standard out" 1> /dev/null
# Redirect STDERR to /dev/null
echo "This is standard error" 2> /dev/null
# Redirect STDOUT and STDERR to /dev/null
echo "This will redirect STDOUT and STDERR" > /dev/null 2>&1
======================================
SCRIPT NAME: document_generator.sh
======================================
#!/bin/bash
# This script is intended to show how to build a document generator
DOCFILE="script_listing"
echo "#!/bin/more" > "$DOCFILE"
ls *.sh > templisting.txt
while IFS= read -r FILENAME; do
if [ -f "$FILENAME" ]; then
echo "======================================" >> "$DOCFILE"
echo "SCRIPT NAME: $FILENAME" >> "$DOCFILE"
echo "======================================" >> "$DOCFILE"
echo ""
echo "$(cat $FILENAME)" >> "$DOCFILE"
fi
done < templisting.txt
chmod 755 "$DOCFILE"
rm templisting.txt
======================================
SCRIPT NAME: env.sh
======================================
#!/bin/bash
echo "This script will give us environment information"
echo ""
echo "================================================"
echo ""
echo "Hello Username: $USER"
echo ""
echo "Your home directory is: $HOME"
echo "Your shell is: $SHELL"
echo "Your language is set to: $LANG"
echo "Your system is: $_system_name"
echo "================================================"
echo ""
======================================
SCRIPT NAME: env_var_example.sh
======================================
#!/bin/bash
# This exercise is intended to display the environment variables
echo $USER
echo $HOME
echo $HISTCONTROL
echo $TERM
======================================
SCRIPT NAME: error_handling.sh
======================================
#!/bin/bash
# This script intends to show the usage of error handling with exit
echo "Change to a directory and list the contents"
DIRECTORY=$1
cd $DIRECTORY 2>/dev/null
if [ "$?" = "0" ]; then
echo "We can change into the directory $DIRECTORY, and here are the contents"
echo "$(ls -alh)"
else
echo "Cannot change directories, exiting with an error no listing"
exit 111
fi
======================================
SCRIPT NAME: errors.sh
======================================
#!/bin/bash
# This is to show exit status types
# It will use `echo $?` to display exit status
# 0 is success, non-zero is failure
# `set -e` wille exit the script once an error occurs
set -e
expr 1 + 5
echo $?
rm test.txt
echo $?
expr 10 + 10
echo $?
======================================
SCRIPT NAME: execution_operator.sh
======================================
#!/bin/bash
# This script is intended to show the usage of execution operators in bash
echo "Enter a number between 1 and 5: "
read VALUE
if [ "$VALUE" -eq "1" ] || [ "$VALUE" -eq "3" ] || [ "$VALUE" -eq "5" ]; then
echo "You entered an odd value of $VALUE."
else
echo "You entered a value of $VALUE."
fi
======================================
SCRIPT NAME: file_descript.sh
======================================
#!/bin/bash
# This script intends to show the usage of assigning descriptors to a file
# for reference -- read/write to file using file descriptor
echo "Enter a filename to read: "
read FILENAME
# '>' denotes 'write', '<' denotes 'read', '<>' denotes 'read/write'
exec 5<>$FILENAME
while read -r FRUIT; do
echo "Fruit: $FRUIT"
done <&5
echo "This file was read on: $(date) by $USER" >&5
# Close out '5' connections
exec 5>&-
======================================
SCRIPT NAME: for_loop.sh
======================================
#!/bin/bash
# This script is intended to show how a for-loop works in bash
echo "List all of the shell script contents of the directory"
SHELLSCRIPTS=$(ls *.sh)
for i in "$SHELLSCRIPTS"; do
DISPLAY="$(cat $i)"
echo "File: $SCRIPT - Contents: $DISPLAY"
done
======================================
SCRIPT NAME: function_exit_return.sh
======================================
#!/bin/bash
# This script intends to show the usage of return and exit in functions
# Global variable declaration
YES=0
NO=1
FIRST=$1
SECOND=$2
THIRD=$3
# =========================== #
# Function definition - start #
# =========================== #
# Check command line params passed in
funcCheckParams() {
# Did we get three?
if [ ! -z "$THIRD" ]; then
echo "We got three parameters."
return $YES
else
echo "We did not get three parameters."
return $NO
fi
}
# =========================== #
# Function definitions - stop #
# =========================== #
# Script - start
funcCheckParams
RETURN_VALS=$? # 0 or 1
# Did we get 3 or not?
if [ "$RETURN_VALS" -eq "$YES" ]; then
echo "We received three params and they are: "
echo "Param 1: $FIRST"
echo "Param 2: $SECOND"
echo "Param 3: $THIRD"
echo ""
else
echo "Usage: function_exit_return.sh [param1] [param2] [param3]"
exit 1
fi
# Script -stop
======================================
SCRIPT NAME: function_organization.sh
======================================
#!/bin/bash
# This script intends to show how to organize scripts to use functions
# Global or script variables
CMDLINE=$1
echo "The script has started!"
# # # # # # # # # # # # # # # # #
# Function definitions -- start #
# # # # # # # # # # # # # # # # #
# Displays a message
funcExample() {
echo "This is an example function."
}
# Display another message
funcExample2(){
echo "This is another example"
}
# Beginning the script
echo "This is the start..."
funcExample
funcExample2
======================================
SCRIPT NAME: function_var_scope.sh
======================================
#!/bin/bash
# This script intends to show variable scope in functions
# Global variable declaration
GLOBALVAR="Globally Visible"
# Function definiton start
# Sample function for function variable scope
funcExample() {
# local variable to the function
LOCALVAR="Locally Visible"
echo "From within the function, the variable is $LOCALVAR"
}
# Function definitions - stopped
# Script start
clear
echo "This step happens first..."
echo ""
echo "GLOBAL variable = $GLOBALVAR (before the function call)"
echo "LOCALVAR variable = $LOCALVAR (before the function call)"
echo ""
echo ""
echo "Calling the function - funcExample()"
echo ""
funcExample
echo ""
echo "The function has been called..."
echo ""
echo "GLOBAL variable = $GLOBALVAR (after the function call)"
echo "LOCALVAR variable = $LOCALVAR (after the function call)"
echo ""
echo "Script end"
======================================
SCRIPT NAME: functions.sh
======================================
#!/bin/bash
# This script is intended to show functions with bash
echo "Hello there! -- outside the function"
functionExample () {
echo "Hello there -- inside the function"
}
singleLineFunction(){ echo "This is a single line function"; }
functionExample
singleLineFunction
======================================
SCRIPT NAME: functions_parameters.sh
======================================
#!/bin/bash
# This script is intended to show functions with parameters
# Global variable declaration
USERNAME=$1
# Function definitions - start
# Calculate age in days
funcAgeInDays() {
echo "Hello $USERNAME, you are $1 years old."
echo "That makes you approximately $(expr $1 \* 365) days old."
}
# Function defintions - stop
# Script start
clear
echo "Enter your age: "
read USERAGE
# Calculate the number of days
funcAgeInDays $USERAGE
======================================
SCRIPT NAME: if_statement.sh
======================================
#!/bin/bash
# This script is intended to show the usage of the 'if'
# conditional statement
echo "================"
echo "Guess the number"
echo "================"
echo ""
echo "Enter a number between 1 and 5: "
read GUESS
if [ $GUESS -eq 3 ]
then
echo "You guessed the correct number!"
fi
if [ $GUESS -eq 4 ]
then
echo "You guessed the correct number!"
fi
======================================
SCRIPT NAME: if_then_else.sh
======================================
#!/bin/bash
# This script is intended to use conditional statements- if/then/else
# and nested if statements
clear
echo "Enter a number between 1 and 3:"
read VALUE
if [ "$VALUE" -eq "1" ] 2>/dev/null; then
echo "You entered #1."
elif [ "$VALUE" -eq "2" ] 2>/dev/null; then
echo "You entered #2."
elif [ "$VALUE" -eq "3" ] 2>/dev/null; then
echo "You entered #3."
else
echo "You didn't enter a number between 1 and 3."
fi
======================================
SCRIPT NAME: ifs_delimiting.sh
======================================
#!/bin/bash
# This script is intended to show how to process a file with delimiters
# IFS = Internal Field Separator
echo "Enter filename to parse: "
read FILENAME
echo "Enter the delimiter: "
read DELIM
IFS=$DELIM
while read -r CPU MEMORY DISK; do
echo "CPU: $CPU"
echo "Memory: $MEMORY"
echo "Disk: $DISK"
done <"$FILENAME"
unset IFS
======================================
SCRIPT NAME: implicit_explicit_vars.sh
======================================
#!/bin/bash
# This script is intended to show the usage of
# implicit and explicit variable definition
# Implicitly declared integer variable
MYVAR=5
echo $MYVAR
echo "$(expr $MYVAR + 5)"
# How to determine 'what' a variable is
declare -p MYVAR # declare -- MYVAR="5"
MYVAR2="Name"
echo $MYVAR2
# Set variable as integer with -i
declare -i NEWVAR=10
echo $NEWVAR
# Declare read-only variable
declare -r READONLY="This is a string we cannot overwrite"
echo $READONLY
READONLY="This is me trying to redeclare the read-only variable"
======================================
SCRIPT NAME: info_box.sh
======================================
#!/bin/bash
# This script is intended to show the usage of the info box with ncurses
# Global variable/default value declaration
INFOBOX=${INFOBOX=dialog}
TITLE="Default"
MESSAGE="Something to say"
XCOORD=10
YCOORD=20
# Function declarations - start
# Display the info box and message
funcDisplayInfoBox() {
$INFOBOX -- title "$1" --infobox "$2" "$3" "$4"
sleep "$5"
}
# Function declarations - stop
# Script start
if [ "$1" == "shutdown" ]; then
funcDisplayInfoBox "WARNING!" "We are SHUTTING DOWN the system..." "11" "21" "5"
echo "Shutting down!"
else
funcDisplayInfoBox "Information..." "You are not doing anything fun..." "11" "21" "5"
echo "Not doing anything..."
fi
# Script end
======================================
SCRIPT NAME: input_box.sh
======================================
#!/bin/bash
# This script intends to show the usage of the input box in bash scripts
# Global variable/default value declaration
INPUTBOX=${INPUTBOX=dialog}
TITLE="Defualt"
MESSAGE="Something to display"
XCOORD=10
YCOORD=20
# ============================= #
# Function declaration -- start #
# ============================= #
# Display input box
funcDisplayInputBox() {
$INPUTBOX --title "$1" --inputbox "$2" "$3" "$4" 2>tmpfile.txt
}
# =========================== #
# Function declaration -- end #
# =========================== #
# Script start
funcDisplayInputBox "Display filename" "Which file in the current directory do you want to display?" "10" "20"
if [ "$(cat tmpfile.txt)" != "" ]; then
echo "$(cat tmpfile.txt)"
else
echo "Nothing to do."
fi
# Script end
======================================
SCRIPT NAME: menu_system.sh
======================================
#!/bin/bash
# This script intends to show how to build a menu system in bash scripts
# Global variable/default value declaration
MENUBOX=${MENUBOX=dialog}
# ============================= #
# Function declaration -- start #
# ============================= #
# Function to display a simple menu
funcDisplayMenuBox() {
$MENUBOX --title "[ M A I N M E N U ]" --menu "Use UP/DOWN arrows to move and select or the number of your choice and ENTER/RETURN" 15 45 4 1 "Display 'Hello world'" 2 "Display 'Goodbye world'" 3 "Display 'Nothing'" X "Exit" 2>choice.txt
}
# =========================== #
# Function declaration -- end #
# =========================== #
# Script start
funcDisplayMenuBox
case "$(cat choice.txt)" in
1) echo "Hello world!";;
2) echo "Goodbye world!";;
3) echo "Nothing";;
X) echo "Exit";;
esac
# Script end
======================================
SCRIPT NAME: message_box.sh
======================================
#!/bin/bash
# This script is intended to show a message box for confirmation in bash scripts
# Global variable/default value declaration
MSGBOX=${MSGBOX=dialog}
TITLE="Default"
MESSAGE="Some message"
XCOORD=10
YCOORD=20
# ============================ #
# Function declaration - start #
# ============================ #
# Dispaly the message box with message
funcDisplayMessageBox() {
$MSGBOX --title "$1" --msgbox "$2" "$3" "$4"
}
# ========================== #
# Function declaration - end #
# ========================== #
# Script - start
if [ "$1" == "shutdown" ]; then
funcDisplayMessageBox "WARNING!" "Please press OK when you are ready to shut down the system" "10" "20"
echo "Shutting down NOW!"
else
funcDisplayMessageBox "Boring..." "you are not asking for anything fun..." "10" "20"
echo "Not doing anything, back to regular scripting..."
fi
# Script - end
======================================
SCRIPT NAME: nested_functions.sh
======================================
#!/bin/bash
# This script is intended to show the usages of nested functions
# Global Variable
GENDER=$1
# Function definitions - start
# Create a human being
funcHuman() {
ARMS=2
LEGS=2
echo "A human has $ARMS arms and $LEGS legs - but what gender are we?"
funcMale() {
BEARD=1
echo "This man has $ARMS arms and $LEGS legs, with $BEARD beard."
echo ""
}
funcFemale() {
BEARD=0
echo "This woman has $ARMS arms and $LEGS legs, with $BEARD beard."
echo ""
}
}
# Function definitions - stop
# Script start
clear
echo "Determining the characteristics of the gender $GENDER"
echo ""
if [ "$GENDER" == "male" ]; then
funcHuman
funcMale
else
funcHuman
funcFemale
fi
======================================
SCRIPT NAME: overriding_events.sh
======================================
#!/bin/bash
# This script is intended to show how to override events with bash scripting
# by overriding/trapping the system exit and execute a custom function
# Global variable/default value declaration
TMPFILE="tempfile1.txt"
TMPFILE2="tempfile2.txt"
trap 'funcMyExit' EXIT
# Function declaration -- start
# Run this exit instead of default exit when called
funcMyExit() {
echo "Exit intercepted..."
echo "Cleaning up temp files..."
rm -rf tempfile*.txt
exit 255
}
# Function declaration -- end
# Script -- start
echo "Write something to tempfile for later use..." > $TMPFILE
echo "Write something to tempfile 2 for later use..." > $TMPFILE2
echo "Trying to copy the indicated file before processing..."
cp -rf $1 newFile.txt 2>/dev/null
if [ "$?" == "0" ]; then
echo "Everything worked out fine."
else
echo "Looks like it did not work out as intended."
exit 1
fi
# Script -- end
======================================
SCRIPT NAME: read_sample.sh
======================================
#!/bin/bash
# This script is intended to show the usage of the `read` command
echo "Enter your First Name: "
read FIRSTNAME
echo "Enter your Last Name: "
read LASTNAME
echo "Enter your age: "
read USERAGE
echo ""
echo "Your full name is: $FIRSTNAME $LASTNAME"
echo "In ten years, you will be $(expr $USERAGE + 10) years old."
======================================
SCRIPT NAME: reading_files.sh
======================================
#!/bin/bash
# This script is intended to show the usage of reading files
echo "Enter a filename to read: "
#Debugging start
set -x
read FILENAME
while read -r FRUIT; do
set +x
echo "Fruit: $FRUIT"
set -x
done < "$FILENAME"
# Stop debugging
set +x
======================================
SCRIPT NAME: shell_expansion.sh
======================================
#!/bin/bash
# This script is intended to show the usage of shell expansion
echo sh{ort,oot,ot}
echo st{il,al}l
# Echo current directory - similar to `pwd`
echo ~+
# Echo old `pwd` direcotry
echo ~-
# Echo a multiplication expression - does not need to be escaped
echo "$[ 2 * 2 ]"
======================================
SCRIPT NAME: special_chars.sh
======================================
#!/bin/bash
# This script is intended to show how to use
# special characters in a bash script
# Using double quotes
echo "\$MY_VARIABLE"
# Using single quotes
echo '$MY_VARIABLE'
# Using quotes in a string
echo "\"\""
======================================
SCRIPT NAME: testfile.sh
======================================
#!/bin/bash
# Tests for existence of indicated filename
FILENAME=$1
echo "Testing for the existence of a file called $FILENAME"
if [ -a $FILENAME ]
then
echo "File $FILENAME does exist."
fi
if [ ! -a $FILENAME ]
then
echo "File $FILENAME does not exist."
fi
echo ""
# Testing multiple expressions in single if statement
FILENAME2=$2
echo "Testing for file $FILENAME2 and readability."
if [ -f $FILENAME2 ] && [ -r $FILENAME2 ]
then
echo "File $FILENAME2 exists and is readable."
fi
if [ ! -f $FILENAME2 ]
then
echo "File $FILENAME2 does not exist."
fi
======================================
SCRIPT NAME: trap_sig.sh
======================================
#!/bin/bash
# This script intends to show the usage of 'trap' and signals
clear
trap 'echo " - Welp, sorry bro, press Q or q!"' SIGINT SIGTERM SIGTSTP
while [ $"CHOICE" != "Q" ] && [ "$CHOICE" != "q" ]; do
echo "MAIN MENU"
echo "========="
echo "1) Choice One"
echo "2) Choice Two"
echo "3) Choice Three"
echo "Q) Quit/Exit"
echo ""
read CHOICE
clear
done
======================================
SCRIPT NAME: while_loop.sh
======================================
#!/bin/bash
# This script is intended to show the usage of a while-loop
echo "Enter the number of times to display the 'hello world' message:"
read DISPLAYNUMBER
COUNT=1
while [ $COUNT -le $DISPLAYNUMBER ]; do
echo "Hello world - $COUNT"
COUNT="$(expr $COUNT + 1)"
done