What does the following script do?
#!/bin/bash
echo $(ls|grep -E "*\.$1$"|wc -l)
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.
Get Answers For Free
Most questions answered within 1 hours.