Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hdd29-CS265-sp19
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdd29
hdd29-CS265-sp19
Commits
f576218d
Commit
f576218d
authored
6 years ago
by
hdd29
Browse files
Options
Downloads
Patches
Plain Diff
lab03
parent
a3d94742
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
lab03/args.bash
+87
-0
87 additions, 0 deletions
lab03/args.bash
lab03/count.bash
+22
-0
22 additions, 0 deletions
lab03/count.bash
lab03/eg.bash
+167
-0
167 additions, 0 deletions
lab03/eg.bash
lab03/rv.bash
+14
-0
14 additions, 0 deletions
lab03/rv.bash
with
290 additions
and
0 deletions
lab03/args.bash
0 → 100755
+
87
−
0
View file @
f576218d
#!/bin/bash
# args - shows how to look at command-line args
#
# Kurt Schmidt
# 1/04
#
# NOTES: Run w/quoted input, like:
# args.bash a "b c" d
#
debugOn
=
"n"
read
-p
"Do you want to see the script as it executes? (y/[n]) => "
\
debugOn
if
[
"
$debugOn
"
==
"y"
-o
"
$debugOn
"
==
"Y"
]
;
then
set
-x
# very useful switch to the set command
fi
echo
"You passed in
$#
arguments"
if
[
-z
$1
]
;
then
echo
-e
"
\n
Hey, try passing some arguments in this time!
\n
"
exit
1
fi
if
((
$#
< 3
))
;
then
echo
-e
"
\n
Okay, at least 3 arguments. Make it mildly interesting.
\n
"
exit
2
fi
echo
-e
"
\n
Okay,
\$
0, the name of the script, is:
$0
"
echo
-e
"
\n
Here are the command line args:
\n\t
$*
"
echo
-e
"
\n
One way of going through the args:"
echo
"
$1
$2
$3
..."
echo
-e
"
\n
Be careful! Only works for single digits. Past 9 this is better:"
echo
"
${
1
}
${
2
}
${
3
}
..."
echo
-e
"
\n
We could loop over the arguments directly (
\$
*):"
i
=
0
for
arg
in
$*
;
do
((
i+
=
1
))
echo
-e
"
$i
\t
$arg
"
done
echo
echo
-e
"
\n
We could loop over the arguments directly (
\"\$
*
\"
):"
i
=
0
for
arg
in
"
$*
"
;
do
((
i+
=
1
))
echo
-e
"
$i
\t
$arg
"
done
echo
echo
-e
"
\n
Not so good. We could try this (
\$
@):"
i
=
0
for
arg
in
$@
;
do
((
i+
=
1
))
echo
-e
"
$i
\t
$arg
"
done
echo
echo
-e
"
\n
Not so good. We could try this (
\"\$
@
\"
):"
i
=
0
for
arg
in
"
$@
"
;
do
((
i+
=
1
))
echo
-e
"
$i
\t
$arg
"
done
echo
echo
-e
"
\n
Or, we could use the shift built-in command,"
echo
-e
"(but we lose them when we're done):"
argList
=
"
$*
"
# save the list for later, maybe
i
=
0
while
[
!
-z
"
$1
"
]
;
do
((
i+
=
1
))
echo
-e
"
$i
\t
$1
"
shift
done
echo
echo
-e
"
\n
See, now
\$
1 is:
\"
$1
\"
All gone."
This diff is collapsed.
Click to expand it.
lab03/count.bash
0 → 100755
+
22
−
0
View file @
f576218d
#!/bin/bash
# args - shows how to look at command-line args
#
# Hanh Do Phung (Teddy)
# 04/17/2019
#
# NOTES: This program prints the filename, number of lines, number of words to stdout for each file in the working directory
for
file
in
*
do
echo
"
$file
$(
cat
$file
|
wc
-l
-w
)
"
done
#for f in *; do cat "$f"; done
#This test for directory
This diff is collapsed.
Click to expand it.
lab03/eg.bash
0 → 100755
+
167
−
0
View file @
f576218d
#!/bin/bash
# eg.bash - just shows examples of the basic components of bash scripting
#
# Kurt Schmidt
# 1/04
#
# Platform: Linux 2.6.18.6
#
# EDITOR: tabstop=2, cols=80
#
# This is a comment
#
listFile
=
"listOfOpenDirs"
debugOn
=
"n"
read
-p
"Do you want to see the script as it executes? (y/[n]) => "
debugOn
if
[
"
$debugOn
"
==
"y"
-o
"
$debugOn
"
==
"Y"
]
;
then
set
-x
# very useful switch to the set command
fi
# You can run simple commands:
echo
-e
"Hello
$USER
\n
"
# find all .html files (just files, not directories or links):
find
.
-type
f
-name
"*.html"
-print
# find *all* html files (.htm, .html, .HTM, .HTML):
find
.
-type
f
-name
"*.[hH][tT][mM]*"
-print
# find all files modifed in the last day:
find
.
-type
f
-mtime
-1
-print
# find all the emails in your default mail directory that mention Heidi,
# save to file
find ~/.Maildir
-type
f
-name
'*.html'
-exec
grep
Heidi
{}
\;
-print
>
heidi.list
# find and delete all backups left by vim (*~) in all subdirectories:
find
.
-name
"*~"
-exec
\r
m
{}
\;
-print
# find files out in /tmp that should be cleaned up, remove 'em
#find /tmp -user $USER -mtime +1 -exec \rm -i -rf {} \;
# see if Kurt is grading (on this machine) ...
ps
-ef
|
grep
kschmidt |
grep
grade
# VARIABLES
str1
=
"hello"
# Note that lack of spaces around the '='
str2
=
"World"
echo
-n
"
$str1
"
# the -n suppresses the newline
echo
$str2
str3
=
"
${
str1
}${
str2
}
"
# alternate form, nice when you don't want spaces
echo
-e
"
\t\t
$str3
"
# the -e allows C-style escape characters in string
echo
# CONDITIONALS
if
[
"
$str1
"
\>
"
$str2
"
]
;
then
echo
"
$str1
comes before
$str2
"
else
echo
"
$str2
comes before
$str1
"
fi
if
[[
"
$str1
"
<
"
$str2
"
]]
;
then
# note that caps come before lowercase
echo
"
$str1
comes before
$str2
"
else
echo
"
$str2
comes before
$str1
"
fi
x
=
3
# integer arithmetic only
y
=
5
if
((
x < y
))
;
then
echo
"x is less than y"
((
x
=
y + 2
))
elif
((
x
==
y
))
;
then
echo
"x is equal to y"
else
echo
"x is greater than y"
((
y
=
x - 1
))
fi
# Careful about base
echo
$((
017
))
echo
$((
0
x23
))
echo
"x is now
$x
, and y is
$y
"
echo
# LOOPS
# Look for open class directories
for
user
in
cam23 rad44 kschmidt
;
do
if
[[
-r
~
${
user
}
/CS265
]]
;
then
echo
$user
>>
$listFile
fi
done
cat
$listFile
if
[[
-f
$listFile
]]
;
then
for
user
in
$(
cat
$listFile
)
;
do
# for user in `cat $listFile` ; do
echo
"Mailing
$user
..."
#mail -s "Close class directories!" $user < /dev/null
done
fi
resp
=
"y"
while
[[
"
$resp
"
==
"y"
]]
;
do
read
-p
"Would you like to continue this loop (y/n)? => "
resp
done
resp
=
"y"
while
[[
"
$resp
"
!=
"n"
&&
"
$resp
"
!=
"N"
]]
;
do
read
-p
"Would you like to continue this loop (y/n)? => "
resp
done
# a C-style for loop:
for
((
i
=
1
;
i<
=
10
;
i++
))
;
do
echo
${
i
}
Q
done
echo
-e
"
\n
You're welcome!
\n
"
# FUNCTIONS
# Functions are nice, can be grouped into "include" files, and sourced
# when needed.
function
foo
# this doesn't mean no args
{
if
[[
!
-d
~/tmp
]]
;
then
mkdir
~/tmp
chmod
700 ~/tmp
fi
listFile
=
"~/tmp/deleteMe"
# be nasty to caller
echo
"foo was here w/args
$*
"
>>
$listFile
local
resp
=
"notAnIssue"
# local variable
for
arg
in
"
$@
"
;
do
echo
$arg
done
echo
"I'm returning 13, because I can"
return
13
}
# to call the function:
foo these are my args
echo
"foo returned
$?
"
echo
"
\$
listFile is now:
$listFile
"
echo
"
\$
resp is still:
$resp
"
This diff is collapsed.
Click to expand it.
lab03/rv.bash
0 → 100755
+
14
−
0
View file @
f576218d
#!/bin/bash
# rv - just playing w/the exit command
#
# Kurt Schmidt
# 1/04
#
if
[[
-z
$1
]]
;
then
echo
-e
"
\n
Hey, try passing a numeric argument in this time!
\n
"
exit
fi
exit
$1
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment