Question

In: Computer Science

Task 2.5: Write a script that will ask the user for to input a file name...

Task 2.5: Write a script that will ask the user for to input a file name and then create the file and echo to the screen that the file name inputted had been created

1. Open a new file script creafile.sh using vi editor

# vi creafile.sh

2. Type the following lines

#!/bin/bash

echo ‘enter a file name: ‘

read FILENAME

touch $FILENAME

echo “$FILENAME has been created”

3. Add the execute permission

4. Run the script #./creafile.sh

5. Enter the file name you want to create

6. Check whether file is created

-------------------------------------------------------------------------------------------------

Task 3.4 Challenge Exercises

a.Write Script to see current date, time, username, and current directory.

b.Take the script from Task 2.5 and write it so it does not create a file if no input is received.

c. In this exercise, you will create a script based on case statement.

d. Write a Shell using for loop to print three strings.

e. Write a bash Script to reverse a given positive integer.

Solutions

Expert Solution

Task 2.4
***********

#!/bin/bash

echo 'enter a file name: '
read FILENAME
touch $FILENAME
echo "$FILENAME has been created"

Task 3.5
**********

#!/bin/bash
i=0
while [ $i -ne 5 ]
do

echo "1.Write Script to see current date, time, username, and current directory"
echo "2.Take the script from Task 2.5 and write it so it does not create a file if no input is received."
echo "3. Write a Shell using for loop to print three strings."
echo "4. Write a bash Script to reverse a given positive integer."
echo "5. exit"

echo "Enter Your choice: "
read INPUT_STRING

case $INPUT_STRING in
   1)
       echo "Current Date/Time is: " `date`
       echo "Current user is: " `whoami`
       echo "Current directory is: " `pwd`
       ;;
   2)
       echo 'enter a file name: '
       read FILENAME
       if [ -z "$FILENAME" ]
       then
           echo "you have not provided any file name"
           exit
       else
       touch $FILENAME
       echo "$FILENAME has been created"
       fi
       ;;
   3)
       echo "For loop to print string 3 times:"
       for ((a=0;a<3;a++))
       {
           echo "Hello World..."
       }
       ;;
   4)
       read -p "Enter a number to reverse: " num
       echo $num | rev
       ;;
   5)
       echo "Bye"
       i=5;
       exit
       ;;
   *)
       echo "Sorry, I don't understand"
       ;;
esac
done



if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)


Related Solutions

Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
Name the script thirsty.sh. Ask the user if they are thirsty. Read the user's response. If...
Name the script thirsty.sh. Ask the user if they are thirsty. Read the user's response. If they answer no or No, print an appropriate message and exit. If they answer yes or Yes, ask what they would like to drink. Read the user's response. If they answer water print "Clear crisp and refreshing." If they answer beer print "Let me see some id." If they answer wine print "one box or two." If they answer anything else print "Coming right...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Write a program that will ask for the user to input a filename of a text...
Write a program that will ask for the user to input a filename of a text file that contains an unknown number of integers. And also an output filename to display results. You will read all of the integers from the input file, and store them in an array. (You may need to read all the values in the file once just to get the total count) Using this array you will find the max number, min number, average value,...
Name the script while.sh. Ask the user to enter a positive integer. You can assume that...
Name the script while.sh. Ask the user to enter a positive integer. You can assume that the user will enter a positive integer (input validation for a positive number not required). Use a while loop to print all integers from 0 up to and including the integer entered. Each integer should be printed on a line by itself and nothing else should print. This is for Linux. I have not done anything on this script. Please help with simplistic commands...
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
Create a project that gets input from the user. ( Name the project main.cpp) Ask the...
Create a project that gets input from the user. ( Name the project main.cpp) Ask the user for a value for each side of the triangle. Comment your code throughout. Include your name in the comments. Submit the plan-Psuedo code (include Flowchart, IPO Chart) and the desk check with each submission of your code. Submit the plan as a pdf. Snips of your output is not a plan. Save the plan and desk check as a pdf Name the code...
Using the given file, ask the user for a name, phone number, and email. Display the...
Using the given file, ask the user for a name, phone number, and email. Display the required information. These are the Files that I made: import java.util.Scanner; public class Demo5 { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("New number creation tool"); System.out.println("Enter name"); String name = keyboard.nextLine(); System.out.println("Enter phone number"); String phoneNumber = keyboard.nextLine(); System.out.println("Enter email"); String email = keyboard.nextLine(); Phone test1 = new SmartPhone(name, phoneNumber, email); System.out.print(test1); System.out.println("Telephone neighbor: " + ((SmartPhone) test1).getTeleponeNeighbor()); }...
Write a program that asks the user for a file name. The file contains a series...
Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in the array 5)...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT