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: Looping and special variable operators - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Solution: Looping and special variable operators
- [Instructor] Let's look at solutions to those problems. So the first one was echoing all the command line arguments. So we'll do a while loop, while $# is greater than zero. $# is the number of remaining command line arguments. So if we just run that and we give it a few, it prints them out, echoing 'em out one per line. If we look at the second one, we're using the colon dash to check on null variables. If we look at the file, it's not set. So what should happen is file should get set to be temp data file. So let's give that a try. We see the file is nothing and file got set to that. Now let's export and set the file to some value. We'll call it, let's say ./results. Then we'll run it again and we see file is ./results using that colon dash. And then the third one. Third one, we go into a subdirectory called Cfiles. We do a list there, we see some .Cfiles, but we also see the solution here, challenge3.sh. So we're going to loop over all the .Cfiles `and for everyone, we're going to…
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
-
-
-
-
-
Defining filters and using head, tail, and wc3m 18s
-
(Locked)
The use of sed for powerful scripting5m 55s
-
(Locked)
Using AWK5m 22s
-
(Locked)
Positional parameters and curly braces for variables3m 40s
-
(Locked)
Shell parameter expansion3m 47s
-
(Locked)
Challenge: Looping and special variable operators1m 12s
-
(Locked)
Solution: Looping and special variable operators2m 23s
-
(Locked)
Challenge: sed and AWK1m 33s
-
(Locked)
Solution: sed and AWK3m 17s
-
-
-