Visit Our UNIX and Linux User Community

Help with date command in bash shell programming

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with date command in bash shell programming
# 1  
Old 04-24-2009
Question Help with date command in bash shell programming

Doubt #1
I have a program that I want the user to input date. When the user inputs the date, is it able to format it to system date dd-mm-yyy and then echo the value into a text file?

If the above is not going to work, I tried to have the system date appear in the user input field and when the user enters to continue, the date shown can be echoed into a text file? The date command that I used is "date +%d-%m-%y".

My codes are something lk this:
echo -en "Date Purchased: "
read datePurchased
echo "${datePurchased} >> a.txt

Please do help me if you know of a way as I just started learning bash shell programming and its really difficult!! Smilie

Thanks in advance !

Last edited by Yogesh Sawant; 04-24-2009 at 06:02 AM.. Reason: added code tags
# 2  
Old 04-24-2009
date | read datePurchased

echo "$datePurchased" >> a.txt
# 3  
Old 04-24-2009
hi amitranjansahu

have tried your codes.. i don't think it works at my end..Smilie
# 4  
Old 04-24-2009
whats the error u r getting can you post that

as i understand you want to redirect the system date to a file.Pls Correct me if i am wrong.

in my solaris machine here is the out put of the code.

amit@server11 ars/amit1 $ date | read datePurchased
amit@server11 ars/amit1 $ echo "$datePurchased"
Fri Apr 24 11:40:54 MEST 2009
# 5  
Old 04-24-2009
What format is the date which the user will type?
Please give examples.
# 6  
Old 04-24-2009
Originally Posted by methyl
What format is the date which the user will type?
Please give examples.
The user are free to type in any format but it is advisable to type in "ddmmyyyy". I think there needs to be a function or some lines of code to format the user input date to be similar to the system date.Smilie
# 7  
Old 04-24-2009
You can use zenity to input a date in a graphical box with the --calendar switch. Users like graphical boxes and zenity does a very nice job of extending the possibilities of shell scripts.

Previous Thread | Next Thread
Test Your Knowledge in Computers #317
Difficulty: Easy
Ada Lovejoy is often considered the first computer programmer.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I apply 'date' command to specific columns, in a BASH script?

Hi everyone, I have a situation in which I have multiple (3 at last count) date columns in a CSV file (, delim), which need to be changed from: January 1 2017 (note, no comma after day) to: YYYY-MM-DD So far, I am able to convert a date using: date --date="January 12, 1990" +%Y-%m-%d ... (7 Replies)
Discussion started by: richardsantink
7 Replies

2. UNIX for Dummies Questions & Answers

Which of the following command displays your login shell in bash shell?

Options:: A)$shell B)echo $ bash C)echo $ O D)$ O (1 Reply)
Discussion started by: raghugowda
1 Replies

3. Shell Programming and Scripting

Chunks of bash shell programming

I am going to provide a chunks of codes that I do not understand. Please help with them in a layman's terms. 1) ${DEBUG:-0} -------------------------------------------------------------------------- 2) print "${1}" ... (7 Replies)
Discussion started by: lg123
7 Replies

4. Homework & Coursework Questions

Bash Shell Programming assignment.

Please take a look I am stuck on step 4 1. The problem statement, all variables and given/known data: #!/bin/bash ### ULI101 - ASSIGNMENT #2 (PART A) - DUE DATE Wed, Aug 3, 2011, before 12 midnight. ###==================================================================================== ###... (13 Replies)
Discussion started by: almirzaee
13 Replies

5. Shell Programming and Scripting

date command in a shell script

It's perhaps a dummy question... but I don't find my way! 1) When I put the date command in a variable, it is ok and here the code : WEEK_DAY=`date +%w` DAY=`date +%Y%m%d` echo WEEK_DAY : "$WEEK_DAY" echo DAY : "$DAY" 2) I should to get direct the date and not in a variable, like : echo... (3 Replies)
Discussion started by: hiddenshadow
3 Replies

6. Shell Programming and Scripting

Creating a command on a BASH shell

Hi all. Suppose I have the following function in an executable file named "HOLA": ------------------------ function hola { echo "Hola ${@}."; } ------------------------ In addition, suppose that I want to execute the file so I can input my name next to ./HOLA. I mean,... (4 Replies)
Discussion started by: hresquivelo
4 Replies

7. UNIX for Dummies Questions & Answers

unix command - bash shell

Hey all, I need to know how many lines of C code are in a source bundle. I have extracted the bundle and hence there is a big directory tree with C files everywhere. So far I have something like: find . -name "*.c" | grep \ ./*/*/*/*/*/* obviously wrong, if someone could help me out... (3 Replies)
Discussion started by: zigga15
3 Replies

8. UNIX for Dummies Questions & Answers

more command does not work in bash shell

is there a different command to display contents of a file on the output in bash shell? i tried more and it does not work. (7 Replies)
Discussion started by: npatwardhan
7 Replies

9. Shell Programming and Scripting

substring command works but only in BASH shell

I am having trouble running a .sh file. The code 'x=${file_name:0:$z-11}' is giving me a bad substitution error. However when I run in BASH it works. Thing is when this goes to production the .sh will not be running in BASH. Is there a way to substring a string not in BASH or a way to invoke... (2 Replies)
Discussion started by: edwardtk11
2 Replies

10. Shell Programming and Scripting

Using variable with cp command in bash shell

Hi, I am trying to write script to copy some files(/ppscdr/cdrp2p/temp/) from one directory to another directory using shell script. see the script below, #!/bin/sh -f dir_name=20061105 mkdir ${dir_name} cd /ppscdr/cdrp2p/temp pwd cp p2p${dir_name}*.*... (4 Replies)
Discussion started by: maheshsri
4 Replies

Featured Tech Videos