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 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).
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,...
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
c++ In this program ask the user what name they prefer for their file, and make...
c++ In this program ask the user what name they prefer for their file, and make a file, the file name should za file. Get a number from the user and save it into the create file. should be more than 20 number in any order. print out all 20 numbers in a sorted array by using for loop, last print out its total and average. At last create a function in which you will call it from main and...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT