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

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…

Contents