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

Script 3: Ask the user for a file's name If the file exists, ask them if...
Script 3: Ask the user for a file's name If the file exists, ask them if they would like to (C)opy, (M)ove, or (D)elete it by choosing C, M, or D If the user chooses C, ask for the destination directory and move it there If the user chooses M, ask for the destination directory and move it there If the user chooses D, delete the file. Ensure that the user enters only C, M, or D, warning them about...
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 script that prompts the user for a pathname of a file or directory and...
Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).
File IO Java question • Ask the user to specify the file name to open for...
File IO Java question • Ask the user to specify the file name to open for reading • Get the number of data M (M<= N) he wants to read from file • Read M numbers from the file and store them in an array • Compute the average and display the numbers and average.
Question 1: Write a Java program that prompts the user to input a file name (existing...
Question 1: Write a Java program that prompts the user to input a file name (existing text file), then calculate and display the numbers of lines in that file. Also calculate and display the length of the longest line in that file. For example, if the input file has the following lines: Hello This is the longest line Bye The output should be: The file has 3 lines. The longest line is line 2 and it has 24 characters. Test...
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,...
Ask the user for their name Create a file called "daily.dat" within the home directory Ask...
Ask the user for their name Create a file called "daily.dat" within the home directory Ask the user for a line of text that the system should save to the file Add to the file the line of text entered by the user Ask the user for a second line of text that the system should save to the file Append at the end of the file the line of text entered by the user Create a copy of the...
In Kali Linux Write a script that ask the user to enter an IP address and...
In Kali Linux Write a script that ask the user to enter an IP address and a port number, then use the provided entries from the user to perform a query on your local network and determine if the given port is open on the provide network. Need to submit solutions for both below. 1.A short report showing the functionality of your code 2. your bash script
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT