From the course: Linux: Bash Shell and Scripts

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenges: Using local variables in functions, loops, and arithmetic

Challenges: Using local variables in functions, loops, and arithmetic - Linux Tutorial

From the course: Linux: Bash Shell and Scripts

Start my 1-month free trial

Challenges: Using local variables in functions, loops, and arithmetic

- [Instructor] Let's do some challenges of writing some scripts. Let's start out with a function. So, you should write a Bash script that has a function called f. The function creates a local variable A, sets it to one, and then prints it out. That's in the function. Outside of the function, in your shell script you wanna set A=2, and we're doin a capital A here. Then it calls f, then it prints the A after f returns. So we wanna see if the local variable A in the function, really is local and it doesn't change the A that is used outside of the function. For another script, we want one that does a for loop, and we want it to loop over all the files in usr bin, and we're gonna assume no filename in usr bin has a space in it. And then for each filename, we're gonna look to see if inside the file, inside the binary, exists a string unable to fork. And if it does, then we wanna print out the name of that file. So we give you part of the code. So you're gonna want an if that uses the…

Contents