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 - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
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…
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
-
-
-
-