Skip to content

Commit 738fa59

Browse files
authored
Update III Control Statements in Bash Scripting.py
1 parent 633ef71 commit 738fa59

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

Introduction to Bash Scripting/III Control Statements in Bash Scripting.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
- Use an IF statement and grep to check if the sfile variable contains SRVM_ AND vpt inside.
8888
- Inside the IF statement, move matching files to the good_logs/ directory.
8989
- Try your script on all of the files in the directory (that is, run it four times - once for each file). It should move only one of them.
90-
"""
90+
"""
9191
# Create variable from first ARGV element
9292
sfile=$1
9393

@@ -184,3 +184,61 @@
184184
185185
Answer : It will run forever because emp_num isn't incremented inside the loop.
186186
"""
187+
188+
"""
189+
### Cleaning up a directory
190+
191+
Instructions
192+
193+
- Use a FOR statement to loop through (using glob expansion) files that end in .py in robs_files/.
194+
- Use an IF statement and grep (remember the 'quiet' flag?) to check if RandomForestClassifier is in the file. Don't use a shell-within-a-shell here.
195+
- Move the Python files that contain RandomForestClassifier into the to_keep/ directory.
196+
"""
197+
# Create a FOR statement on files in directory
198+
for file in robs_files/*.py
199+
do
200+
# Create IF statement using grep
201+
if grep -q 'RandomForestClassifier' $file ; then
202+
# Move wanted files to to_keep/ folder
203+
mv $file to_keep/
204+
fi
205+
done
206+
207+
208+
repl:~/workspace$ cd /home/repl/workspace
209+
repl:~/workspace$ bash script.sh
210+
211+
"""
212+
*** CASE statements
213+
*** basic syntax
214+
>>>>>> case 'something' in
215+
216+
*** regex for pattern
217+
>>>>>> Air* : 'starts w/ Air'
218+
>>>>>> *hat* : 'contains hat'
219+
220+
***syntax
221+
case 'something' in
222+
PATTERN1)
223+
COMMAND1;;
224+
PATTERN2)
225+
COMMAND2;;
226+
*)
227+
DEFAULT COMMAND;;
228+
esac
229+
230+
eg: #new case statement
231+
case $(cat $1) in
232+
*Sydney*)
233+
mv $1 sydney/ ;;
234+
*melbourne*|*brisbane*)
235+
rem $1 ;;
236+
*canberra*)
237+
mv $1 "IMPORTANT_$1" ;;
238+
*)
239+
echo "no cities found!" ;;
240+
esac
241+
"""
242+
243+
244+

0 commit comments

Comments
 (0)