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

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…

Contents