From the course: Learning Linux Shell Scripting
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution: Counter - Linux Tutorial
From the course: Learning Linux Shell Scripting
Solution: Counter
(soft bell chiming) - [Instructor] So, how did you do with the challenge? Let me show you my solution. So, we're gonna say touch, counter.sh. Change mode, 755 counter.sh. Atom, counter.sh. We'll put in the sha-bang. First, we'll need a counter. So, we'll say count equals one. Then we need something that tells us when to stop, and this value is coming from the user. So, we'll call this end, that's gonna equal to dollar sign one. Then we'll create our while loop. We'll say while, dollar sign count is less than or equal to dollar sign, end, do. And we're gonna have echo count equals dollar sign count. Then we need to increment the counter. Remember, we have two sets of parentheses here. That is count, plus plus. And then we end the loop with a done. And we're gonna echo, loop, finished. And exit, zero. Save this with a control S. Go to the terminal, do the counter sh and then give it a number value. So, let's give it 10. We can save counts one to 10. And just for giggles let's try, 20…
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.