From the course: Linux: Bash Shell and Scripts
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Solutions: Looping, special variable operators, sed, and AWK - Linux Tutorial
From the course: Linux: Bash Shell and Scripts
Solutions: Looping, special variable operators, sed, and AWK
(exciting music) - So our first challenge was to print out the command line argument, one per line. So let's see how we could do that. So we could do a while loop and we're gonna use dollar sign, pound which is the number of command line arguments. While that's greater than zero, we're gonna loop. And we're gonna echo out the first one and then do a shift. And then see if there's any left. If there's any left, we'll print out the first one and then shift, so let's run that. And we'll give it the sequence A through F, there we go. Each of the command line arguments, one per line. Our second challenge was to assign a variable called File a default value if TheFile wasn't set. So let's see how we could do that. So File is assigned and we're using the colon dash operation and that's just what it does. If the TheFile is null or not set, then File's gonna get tmp/data.file}. If TheFile is set it's gonna get TheFile. So we're gonna print out at the end what the value is in File and what the…
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
-
-
-
-
-
(Locked)
Defining filters and using head, tail, and wc5m 3s
-
(Locked)
Using sed and AWK for more powerful scripting13m 22s
-
(Locked)
Positional parameters and operators with braces10m 7s
-
(Locked)
Challenges: Looping, special variable operators, sed, and AWK1m 54s
-
(Locked)
Solutions: Looping, special variable operators, sed, and AWK2m 25s
-
(Locked)
-
-