From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Solution: Variables in functions, loops, and arithmetic - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Solution: Variables in functions, loops, and arithmetic
(upbeat music) - [Instructor] Let's take a look at those challenges. There were some good ones. So in your lab exercises Ch02 directory you should have these files. For challenge one we have a solution. We define a function f, we make the variable A local with typeset command. And when we run it, we see that after f A is two because when we changed A to be one, in function f we were changing the local one, that was the key concept there. For the second challenge, let's take a look at the solution there. What we're supposed to do is loop overall the files and user bin and echo out the name of any one of them that has the string unable to fork in it. So what we do in the script is change directory to user bin and then we do a for loop for i in star that'll match all the names. And in the loop we check to make sure that it's a file, not a subdirectory. And if it is then we go in the if then, then we do a strings on the file. Piping that into grep, the quiet mode, checking for a match in…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
The typeset and declare commands for variables and arrays5m 59s
-
(Locked)
Looping with while sequences and reading input6m 12s
-
(Locked)
Looping with for, the seq command, and backticks8m 3s
-
(Locked)
Defining functions and using return and exit4m 17s
-
(Locked)
Using file descriptors, file redirection, and pipes7m 23s
-
(Locked)
Here documents3m 54s
-
(Locked)
Open and close file descriptors5m 22s
-
(Locked)
Control-flow if-then-else with the test command4m 42s
-
(Locked)
Case statements3m 45s
-
(Locked)
Using arithmetic operators3m 26s
-
(Locked)
Challenge: Variables in functions, loops, and arithmetic2m 46s
-
(Locked)
Solution: Variables in functions, loops, and arithmetic2m 42s
-
-
-
-