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.
The script file should contain the following code as its very first line: #binbash
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 :
Write a script that takes a file name as commandline input and counts the number of lines in the file. You can use thewccommand with theloptions to count the number of lines in the file. You can use the abovementioned commandline variables to get the filename assume the filename does not have any spaces Use command substitution$commandto capture the output of thewccommand and store it in a variable.
Question :
Write a script that takes a directory name as commandline 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
