Question

What does the following script do? #!/bin/bash echo $(ls|grep -E "*\.$1$"|wc -l)

What does the following script do?

#!/bin/bash

echo $(ls|grep -E "*\.$1$"|wc -l)

Homework Answers

Answer #1

First command:

#!/bin/bash is used for the login of user in Linux operating system.And using this command invokes bash command interpreter.It tells the linux interpretr that execute the files as bash script. Its known as Shebang which contains path.

Second command :
it will list all the contents using ls and then grep (filter) the regular expression matching with the format (*\.$1$) from th content and then print the total count of the filtered regualr expression if it matches.

If anything matches with the pattern in double quotes then it will print the count of matches matched with the above regular expression and If there are no matches it will print 0

-->echo command is used for printing

--> ls is used for list files or directiories

--> | is the pipeline operator , pipe the next command

--> grep is used to filter or searching

--> -E is switch with grep command and it is used to interpret pattern as an extended regular expression.

and wc -l  counts the total number of lines.

The output of above command is 0 if nothing is matched with pattern( "*\.$1$") mentioned in command.

The output of above command will not be 0 if anything is macthed with pattern given in command.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line...
Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? I am using this on Docker Quickstart Terminal version 19. I can't seem to execute it on the command line or get it to work. I'm not sure what I have to fix. This is what I have written so far. ---------------------------------------------------- JennyM07@DESKTOP-3XD60LM MINGW64 ~/CIT270/Lab_1$ ls -l total 1 -rwxr-xr-x 1 JennyM07 197121 100 Aug 26 21:41 file8.sh* -rw-r--r-- 1 JennyM07...
1. It is given that L ~ Bin(n, p), where E(L) = 4 and Var(L) =...
1. It is given that L ~ Bin(n, p), where E(L) = 4 and Var(L) = 3.5. (a) Find the values of n and p (b) Find P(L =10)
1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal...
1. Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5 and log in to the terminal using the user name of root and the password of LINUXrocks!. 2. At the command prompt, type vi diskconfig.sh and press Enter to open a new file for editing called diskconfig.sh in your home directory. Why is it good form to use a .sh extension for shell scripts? 3. Enter the following text into the diskconfig.sh file. As you are typing the contents, ensure...
Consider the following python script mt_q2.py, which defines the function called now(): #!/usr/bin/env python3 # program:...
Consider the following python script mt_q2.py, which defines the function called now(): #!/usr/bin/env python3 # program: mt_q2.py import os def now():     p = os.popen('date +%Y%m%d')     today = p.read().strip()     return today if __name__ == '__main__':     print(now()) Asnwer the following questions: (a) What type of object will be returned by the now() function? (b) If you run the above Python script "python3 mt_q2.py" on a system with real-time clock on Oct 16, 2019 at 10:00 am, what will...
what is the bin-1 gene? how does it relate to Alzheimer's disease?
what is the bin-1 gene? how does it relate to Alzheimer's disease?
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set it equal to the empty string (NAME=””). Create a variable called NAME_LENGTH and set it equal to the length of your last name. Output the value of the NAME variable to show that it is empty. 2. Write a FOR loop that executes as many times as there are letters in your name (use the NAME_LENGTH variable in your condition). Use a CASE statement...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2 – K) S(n) – S(n-1) ;   Assume S(1) = 0, S(2) = 1; (a)    Case 1, Assume K = 1 (b)    Case 2, Assume K = 2 (c)     Case 3, Assume K = 4 Plot all of these on the same plot, for N = 1 to 20
What does the function split do? Explain with an example. ​ ​ def split(L, first): return...
What does the function split do? Explain with an example. ​ ​ def split(L, first): return [b for b in L if b <= first], [b for b in L if b > first]
Problem 4 Scheme. What do the following functions do? (define (blue p l) (= (length l)...
Problem 4 Scheme. What do the following functions do? (define (blue p l) (= (length l) (length (filter p l)))) (define (renmap f x ys) (map (lambda (y) (f x y)) ys)) (define (binmap f xs ys) (map (lambda (x) (renmap f x ys)) xs))
11. 4.21 (What Does this Program Do?) What does the following program print? 1 // Exercise...
11. 4.21 (What Does this Program Do?) What does the following program print? 1 // Exercise 4.21: Mystery2.cpp 2 #include <iostream> 3 using namespace std; 4 5 int main() { 6 unsigned int count{1}; 7 8 while (count <= 10) { 9 cout << (count % 2 == 1 ? "****" : "++++++++") << endl; 10 ++count; 11 } 12 }