Skip to content

Commit 234e54f

Browse files
authored
Add files via upload
1 parent 55187ff commit 234e54f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2417
-1
lines changed

Arithmetic_demo.bash

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
first_num=0
4+
second_num=0
5+
6+
echo -n "Enter the first number --> "
7+
read first_num
8+
echo -n "Enter the second number -> "
9+
read second_num
10+
11+
echo "first number + second number = $((first_num + second_num))"
12+
echo "first number - second number = $((first_num - second_num))"
13+
echo "first number * second number = $((first_num * second_num))"
14+
echo "first number / second number = $((first_num / second_num))"
15+
echo "first number % second number = $((first_num % second_num))"
16+
echo "first number raised to the"
17+
echo "power of the second number = $((first_num ** second_num))"

BuildMenuEnhanced_demo.bash

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
press_enter()
4+
{
5+
echo -en "\nPress Enter to continue"
6+
read
7+
clear
8+
}
9+
10+
selection=
11+
until [ "$selection" = "0" ]; do
12+
echo "
13+
PROGRAM MENU
14+
1 - display free disk space
15+
2 - display free memory
16+
17+
0 - exit program
18+
"
19+
echo -n "Enter selection: "
20+
read selection
21+
echo ""
22+
case $selection in
23+
1 ) df ; press_enter ;;
24+
2 ) free ; press_enter ;;
25+
0 ) exit ;;
26+
* ) echo "Please enter 1, 2, or 0"; press_enter
27+
esac
28+
done

BuildingMenu_demo.bash

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
selection=
4+
until [ "$selection" = "0" ]; do
5+
echo "
6+
PROGRAM MENU
7+
1 - Display free disk space
8+
2 - Display free memory
9+
10+
0 - exit program
11+
"
12+
echo -n "Enter selection: "
13+
read selection
14+
echo ""
15+
case $selection in
16+
1 ) df ;;
17+
2 ) free ;;
18+
0 ) exit ;;
19+
* ) echo "Please enter 1, 2, or 0"
20+
esac
21+
done

CasePattern_demo.bash

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
echo -n "Type a digit or a letter > "
4+
read character
5+
case $character in
6+
# Check for letters
7+
[[:lower:]] | [[:upper:]] ) echo "You typed the letter $character"
8+
;;
9+
10+
# Check for digits
11+
[0-9] ) echo "You typed the digits $character"
12+
;;
13+
14+
# Check for anything else
15+
* ) echo "You did not type a letter or a digit"
16+
esac

CompareTwoDir_demo.bash

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# cmp_dir - program to compare two directories
4+
5+
# Check for required arguments
6+
if [ $# -ne 2 ]; then
7+
echo "usage: $0 directory_1 directory_2" 1>&2
8+
exit 1
9+
fi
10+
11+
# Make sure both arguments are directories
12+
if [ ! -d $1 ]; then
13+
echo "$1 is not a directory!" 1>&2
14+
exit 1
15+
fi
16+
17+
if [ ! -d $2 ]; then
18+
echo "$2 is not a directory!" 1>&2
19+
exit 1
20+
fi
21+
22+
# Process each file in directory_1, comparing it to directory_2
23+
missing=0
24+
for filename in $1/*; do
25+
fn=$(basename "$filename")
26+
if [ -f "$filename" ]; then
27+
if [ ! -f "$2/$fn" ]; then
28+
echo "$fn is missing from $2"
29+
missing=$((missing + 1))
30+
fi
31+
fi
32+
done
33+
echo "$missing files missing"

DetectCommLineArgs1_demo.bash

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
if [ $# -gt 0 ]; then
4+
echo "Your command line contains $# arguments"
5+
else
6+
echo "Your command line contains no arguments"
7+
fi

DetectCommLineArgs_demo.bash

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
if [ "$1" != "" ]; then
4+
echo "Positional parameter 1 contains something"
5+
else
6+
echo "Positional parameter 1 is empty"
7+
fi

FileCommandList1_demo.bash

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
for filename in "$@"; do
4+
result=
5+
if [ -f "$filename" ]; then
6+
result="$filename is a regular file"
7+
else
8+
if [ -d "$filename" ]; then
9+
result="$filename is a directory"
10+
fi
11+
fi
12+
if [ -w "$filename" ];then
13+
result="$result and it is writable"
14+
else
15+
result="$result and it is not writable"
16+
fi
17+
echo "$result"
18+
done

FileCommandList_demo.bash

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
for i in "$@"; do
4+
echo $i
5+
done

FlowCont3_demo.bash

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
for i in word1 word2 word3; do
4+
echo $1
5+
done

FlowControl2_demo.bash

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
echo -n "Enter a number between 1 and 3 inclusive > "
4+
read character
5+
if [ "$character" = "1" ]; then
6+
echo "You entered one."
7+
elif [ "$character" = "2" ]; then
8+
echo "You entered two."
9+
elif [ "$character" = "3" ]; then
10+
echo "You did not enter a number between 1 and 3."
11+
fi

FlowControl2_demo2.bash

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
echo -n "Enter a number between 1 and 3 inclusive > "
4+
read character
5+
case $character in
6+
1 ) echo "You entered one."
7+
;;
8+
2 ) echo "You entered two."
9+
;;
10+
3 ) echo "You entered three."
11+
;;
12+
* ) echo "You did not enter a number between 1 and 3."
13+
esac

FunctionsSample.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
# This doesn't, Work!
3+
# error is the function not found
4+
#function quit {
5+
# exit
6+
#}
7+
#function hello {
8+
# echo Hello!
9+
#}
10+
#hello
11+
#quit
12+
#echo foo
13+
#
14+
#Functions with parameters sample.. From same webpage two examples.
15+
#Im gussing this dont work either http://tldp.org/HOWTO/Bash-Prog-\
16+
#Intro-HOWTO-8.html#ss8.1 or How NOt TO Write Bash
17+
function quit {
18+
exit
19+
}
20+
function e {
21+
echo $1
22+
}
23+
e Hello
24+
e World
25+
quit foo
26+
27+
# function not found line 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# This Program is to Show user the commands to create a bash script
3+
# to execute this program type at terminal ./'I want to write a bash program
4+
clear
5+
echo #########################################################################
6+
echo Showing the command line steps to start a Hello World program
7+
echo *************************************************************************
8+
echo #########################################################################
9+
echo Where you see test.sh, Please rename test.sh
10+
echo *************************************************************************
11+
echo #########################################################################
12+
echo Follow Steps Below...
13+
echo *************************************************************************
14+
echo "'#!/bin/sh' > test.sh # change test.sh"
15+
echo "'echo Hello World' >> test.sh # change test.sh"
16+
echo chmod 755 test.sh # change test.sh
17+
echo nano test.sh # change test.sh
18+
19+
# I want to add an option to ask user if they want to start a new bash \
20+
# program yes \ no?
21+
# if yes\Yes query user for new name, What to call this bash ? ......

ICODE

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# This Program is to Show user the commands to create a bash script
3+
# to execute this program type at terminal ./'I want to write a bash program
4+
clear
5+
echo Showing the command line steps to start a Hello World program
6+
echo Where you see test.sh, Please rename test.sh
7+
echo Follow Steps Below...
8+
echo ####################
9+
echo "echo '#!/bin/bash' > test.sh # change test.sh"
10+
echo "'echo Hello World' >> test.sh # change test.sh"
11+
echo chmod 755 test.sh # change test.sh
12+
echo nano test.sh # change test.sh
13+
# exec '#!/bin/bash' > test.sh
14+
15+
# I want to add an option to ask user if they want to start a new bash \
16+
# program yes \ no?
17+
# if yes\Yes query user for new name, What to call this bash ? ......
18+
19+
#today() {
20+
#echo -n "Today's date is: "
21+
#date +"%A, %B %-d, %Y"
22+
#}
23+
#set +x
24+
echo -n "Please Enter a Filename For Your New Bash Script > "
25+
read text
26+
echo "Your New Bash Script is named: $text"
27+
28+
# I need to figure out how to add .bash to the $text varable
29+
30+
selection=
31+
until [ "$selection" = "0" ]; do
32+
echo "
33+
ICODE MENU
34+
1 - Start a new Bash Script
35+
2 - Start a new HTML Document
36+
3 - start a new Python Idle
37+
4 - Start a new php program
38+
5 - start a New Ruby Code
39+
40+
0 - exit program
41+
"
42+
echo -n "Enter selection: "
43+
read selection
44+
echo ""
45+
case $selection in
46+
1 ) nano $text:.bash ;;
47+
2 ) nano ;;
48+
3 ) idle ;;
49+
4 ) nano ;;
50+
5 ) nano ;;
51+
0 ) exit ;;
52+
* ) echo "Please enter 1, 2, 3, 4, 5, or 0"
53+
esac
54+
done

IcodeEX.bash

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash -
2+
#title :mkscript.sh
3+
#description :This script will make a header for a bash script.
4+
#author :bgw
5+
#date :20111101
6+
#version :0.4
7+
#usage :bash mkscript.sh
8+
#notes :Install Vim and Emacs to use this script.
9+
#bash_version :4.1.5(1)-release
10+
#==============================================================================
11+
12+
today=$(date +%Y%m%d)
13+
div=======================================
14+
15+
/usr/bin/clear
16+
17+
_select_title(){
18+
19+
# Get the user input.
20+
printf "Enter a title: " ; read -r title
21+
22+
# Remove the spaces from the title if necessary.
23+
title=${title// /_}
24+
25+
# Convert uppercase to lowercase.
26+
title=${title,,}
27+
28+
# Add .sh to the end of the title if it is not there already.
29+
[ "${title: -3}" != '.sh' ] && title=${title}.sh
30+
31+
# Check to see if the file exists already.
32+
if [ -e $title ] ; then
33+
printf "\n%s\n%s\n\n" "The script \"$title\" already exists." \
34+
"Please select another title."
35+
_select_title
36+
fi
37+
38+
}
39+
40+
_select_title
41+
42+
printf "Enter a description: " ; read -r dscrpt
43+
printf "Enter your name: " ; read -r name
44+
printf "Enter the version number: " ; read -r vnum
45+
46+
# Format the output and write it to a file.
47+
printf "%-16s\n\
48+
%-16s%-8s\n\
49+
%-16s%-8s\n\
50+
%-16s%-8s\n\
51+
%-16s%-8s\n\
52+
%-16s%-8s\n\
53+
%-16s%-8s\n\
54+
%-16s%-8s\n\
55+
%-16s%-8s\n\
56+
%s\n\n\n" '#!/bin/bash -' '#title' ":$title" '#description' \
57+
":${dscrpt}" '#author' ":$name" '#date' ":$today" '#version' \
58+
":$vnum" '#usage' ":./$title" '#notes' ':' '#bash_version' \
59+
":${BASH_VERSION}" \#$div${div} > $title
60+
61+
# Make the file executable.
62+
chmod +x $title
63+
64+
/usr/bin/clear
65+
66+
_select_editor(){
67+
68+
# Select between Vim or Emacs.
69+
printf "%s\n%s\n%s\n\n" "Select an editor." "1 for Vim." "2 for Emacs."
70+
read -r editor
71+
72+
# Open the file with the cursor on the twelth line.
73+
case $editor in
74+
1) vim +12 $title
75+
;;
76+
2) emacs +12 $title &
77+
;;
78+
*) /usr/bin/clear
79+
printf "%s\n%s\n\n" "I did not understand your selection." \
80+
"Press <Ctrl-c> to quit."
81+
_select_editor
82+
;;
83+
esac
84+
85+
}
86+
87+
_select_editor

0 commit comments

Comments
 (0)