Getting bash shell script to do one thing if user hits enter .

  • Thread starter Thread starter jameson2
  • Start date Start date
  • Tags Tags
    Shell
AI Thread Summary
A bash shell script can be designed to output a specific line in a calendar file based on user input, where an "enter" key press triggers the output of today's date. The 'read' command in bash captures user input, allowing the script to check if the input is empty. If the input is empty, the script can execute a command to print today's date; otherwise, it can process the entered date. However, determining if the input is a valid date can be complex in bash, leading some users to suggest using other programming languages like Python or Perl for better handling. Overall, the discussion emphasizes the simplicity of checking for empty input while highlighting the challenges of validating date formats in bash.
jameson2
Messages
42
Reaction score
0
Getting bash shell script to do one thing if user hits "enter".

I need to write a program that will output a line in a calendar file if a date is entered, or if no date is entered and the user just hits "enter" to ouput the line corresponding to today's date.
I think that it must take the form of an if statement, along the lines of if(date is entered) then print the line, else print today's line. Or maybe if date is entered do such and such, if user hits enter do something else. But I don't know how to translate "user hits enter" into the shell language, or user enters date now that I think about it. Any help would be great. User hit's enter would be the most useful in my opiniono, thanks.
 
Technology news on Phys.org


The bash command 'read' reads from standard input into zero or more shell script variables specified as the targets of the read command. If you specify one variable it will contain the contents of the line entered by the user. Testing whether the entered data is empty (the user just hit return) is easy. Testing whether it is a date, in bash? Do you like to torture yourself? You might want to rethink that and use something like python, perl, tcl, ... -- anything but bash.
 


Well even just something to distinguish between whether the user actually enters any information or just hits enter. I'm fairly new to this...
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top