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.

Challenge: Variables in functions, loops, and arithmetic

Challenge: Variables in functions, loops, and arithmetic

- [Instructor] All right, we've got a few challenges for you. We covered a whole lot in that chapter, and I hope you followed along and tried the examples and so forth because that is really valuable. But we've got a few here to reinforce what we talked about. Number one is write a Bash script where you define a function F, and inside of F, create a local variable called A and set that variable to one and print it out. Then outside of F, set A equals two, call F, and then print A after F returns. We want to see if the function changed the global A. Next question, write a Bash script that uses a for loop to loop over all the files in usr/bin and echo the name of any one of those files that has inside of the file, these are executable programs, the string unable to fork, and we give you a hint. Turns out there's a command called strings, and if you give it a binary file, it'll echo out all the strings in that file. And so then you can grep for that unable to fork. And the minus Q means…

Contents