Bash coder
Budget: ₹600 – ₹1,500 INR
Task 1
Write an interactive bash script that is responsible for setting up a new directory and populating the directory with files.
The user should interactively create the new folder. If the folder already exists, the user should be prompted to delete it. Once the folder has been created, move into the new folder.
Once inside the new folder, make an interactive menu where the user has three options:
• Make a new file
• Print the contents of the working directory into a file called “contents.txt” and output
the file content to the screen.
• Exit the program with a nice message
If an illegal option is entered, notify the user. When making a new file, the user should be prompted for the file name. If the file already exists, tell the user. Properly comment your code for easy understanding.
[20 marks]
Task 2
Download the archive “input.zip” from Canvas and unpack it in your working directory. It will produce a folder with name “input”. Now write a bash script that list out, one at a time, all the files in the “input” folder that are bigger than a specified file size (in bytes) by the user. (You may use wc -c < “filename” command to extract the file size). For each identified file, give the user the option to copy or delete the file, then proceed to the next file until all the files have been processed.
The file size should be provided as command line argument to the script. This argument is mandatory and you must ensure that it is provided.
Use bash functions to implement the copy and delete operations. The function should accept the filename as a single parameter. In the case of delete, simply delete the file. When the user
chooses to copy, prompt for a new name for copying the file and then execute the copy operation.
At the end of the program output the content of the working directory and the input folder. You are free to use multiple functions to solve this task if you want. Properly comment your code for easy understanding.
Write an interactive bash script that is responsible for setting up a new directory and populating the directory with files.
The user should interactively create the new folder. If the folder already exists, the user should be prompted to delete it. Once the folder has been created, move into the new folder.
Once inside the new folder, make an interactive menu where the user has three options:
• Make a new file
• Print the contents of the working directory into a file called “contents.txt” and output
the file content to the screen.
• Exit the program with a nice message
If an illegal option is entered, notify the user. When making a new file, the user should be prompted for the file name. If the file already exists, tell the user. Properly comment your code for easy understanding.
[20 marks]
Task 2
Download the archive “input.zip” from Canvas and unpack it in your working directory. It will produce a folder with name “input”. Now write a bash script that list out, one at a time, all the files in the “input” folder that are bigger than a specified file size (in bytes) by the user. (You may use wc -c < “filename” command to extract the file size). For each identified file, give the user the option to copy or delete the file, then proceed to the next file until all the files have been processed.
The file size should be provided as command line argument to the script. This argument is mandatory and you must ensure that it is provided.
Use bash functions to implement the copy and delete operations. The function should accept the filename as a single parameter. In the case of delete, simply delete the file. When the user
chooses to copy, prompt for a new name for copying the file and then execute the copy operation.
At the end of the program output the content of the working directory and the input folder. You are free to use multiple functions to solve this task if you want. Properly comment your code for easy understanding.
Related categories:
Bash Scripting