Question: A bash script is a file containing bash commands. We must first take the following two steps to make the file executable. 1 . The

A bash script is a file containing bash commands. We must first take the following two steps to make the file executable.
1. The script file should contain the following code as its very first line: #!/bin/bash
This specifies which program bash should be used to interpret the commands in the script.
Next, the script's file permissions should be set to be executable. Recall that this is typically done as follows: chmod +x scriptname
The script can then be run like any other executable file: ./scriptname
Actually, we can also run a script as follows, even without making the script executable, but this is less frequently done.
bash scriptname
Question 1:
Write a script that takes a file name as command-line input and counts the number of lines in the file. You can use thewccommand with the-loptions to count the number of lines in the file. You can use the above-mentioned command-line variables to get the filename (assume the filename does not have any spaces). Use command substitution(`$(command)`)to capture the output of thewccommand and store it in a variable.
Question 2:
Write a script that takes a directory name as command-line input and creates a backup of all the files in the directory. You can use themkdircommand to create a new directory with a unique name (for example, using the current date and time). You can use thecpcommand to copy all the files from the input directory to the new directory and thetarcommand to compress the new directory into an archive. Finally, you can use thermcommand to delete the new directory to clean up.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!