Question

In: Computer Science

Write a Bash script clock.sh that once/second will print the time in the 24-hour clock format...

Write a Bash script clock.sh that once/second will print the time in the 24-hour clock format HH:MM:SS. See "man date" for a command to produce this format of time.

rubric

clock.sh prints h:m:s in 24-hour clock format

clock.sh prints time 1/second

Solutions

Expert Solution

clock.sh prints h:m:s in 24-hour clock format

Answer :

Step 1: First Create file clock.sh

Step 2 : chmod +x clock.sh (Change permission for executable)

Step 3: Open the file clock.sh and copy below thing


#date +"%H:%M:%S" ,specifies the format to display only hours minutes and seconds 
date +"%H:%M:%S"
 

Step 4: Save the file

Step 5: Open the terminal and run below command in terminal

./clock.sh

Step 6: For exit from the program type Cntrl+D

Output :

clock.sh prints time 1/second

Answer :

Step 1: First Create file clock.sh

Step 2 : chmod +x clock.sh (Change permission for executable)

Step 3: Open the file clock.sh and copy below thing

#infinite loop
while true; do
#assigninig the value to the date variable
#date +"%H:%M:%S" ,specifies the format to display only hours minutes and seconds 
 date=$(date +"%H:%M:%S")
 #printing the variable to the terminal
 echo $date
 #put thread to sleep for 1 sec
 sleep 1
done

Step 4: Save the file

Step 5:Open the terminal and run below command in terminal

./clock.sh

Step 6: For exit from the program type Cntrl+D

Output :

Let me know if you need any help :)


Related Solutions

Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm,...
Many people keep time using a 24 hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, it will be 15 (3pm). Write a Python program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Fully Functional Script written in BASH In this section, you will write a fully functional script...
Fully Functional Script written in BASH In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if...
⦁   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...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask...
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask the user to input the number of kilometers they need to travel. - Display the number of equivalent miles for the number. Use formula, Kilometers = miles/0.62137 - Every time the loop runs, it should ask the user if they want to continue, if user enters “Y” or “y”, then the loop runs again, if user enters “N” or “n”, then stop the loop...
In JAVA Write a program that converts a time from 24-hour notation to 12-hour notation. Assume...
In JAVA Write a program that converts a time from 24-hour notation to 12-hour notation. Assume the user will enter the time as a 4-digit number with no colon. Define an exception class called InvalidTimeFormatException. If the user enters an invalid time lime 1065 or 2515, the program should throw and handle an InvalidTimeFormatException. NOTE: Assume the user will enter the time as a 4-digit number with no colon. SAMPLE OUTPUT: Enter time in 24-hour notation: 1614 That is the...
Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa....
Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following functions: a function to convert the time from 24-hour notation to 12-hour notation; a function to convert the time from 12-hour notation to 24-hour notation; a function to display the choices; function(s) to get the input;...
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT