Sponsored Content
Top Forums Shell Programming and Scripting Echo date variable from data input to a script Post 302478169 by iga3725 on Tuesday 7th of December 2010 09:40:16 AM
Old 12-07-2010
Echo date variable from data input to a script

Hi, I'm trying to make a script which you type the year, select the month and day and then create the date in the format 2010-12-7.
Code:
#!/bin/bash

dia () {
echo " Seleccione el dia:"
select file in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Salir
do
case $file in
"1") d=1 ; fecha ;;
"2") d=2 ; fecha ;;
"3") d=3 ; fecha ;;
"4") d=4 ; fecha ;;
"5") d=5 ; fecha ;;
"6") d=6 ; fecha ;;
"7") d=7 ; fecha ;;
"8") d=8 ; fecha ;;
"9") d=9 ; fecha ;;
"10") d=10 ; fecha ;;
"11") d=11 ; fecha ;;
"12") d=12 ; fecha ;;
"13") d=13 ; fecha ;;
"14") d=14 ; fecha ;;
"15") d=15 ; fecha ;;
"16") d=16 ; fecha ;;
"17") d=17 ; fecha ;;
"18") d=18 ; fecha ;;
"19") d=19 ; fecha ;;
"20") d=20 ; fecha ;;
"21") d=21 ; fecha ;;
"22") d=22 ; fecha ;;
"23") d=23 ; fecha ;;
"24") d=24 ; fecha ;;
"25") d=25 ; fecha ;;
"26") d=26 ; fecha ;;
"27") d=27 ; fecha ;;
"28") d=28 ; fecha ;;
"29") d=29 ; fecha ;;
"30") d=30 ; fecha ;;
"31") d=31 ; fecha ;;
"Salir") exit 1;;
 *)
    echo "ERROR: Seleccione correctamente... "
    dia;;
esac
done
}

mes () {
echo " Seleccione el mes:"
select file in enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre Salir
do
case $file in
"enero") m=1 ; dia ;;
"febrero") m=2 ; dia ;;
"marzo") m=3 ; dia  ;;
"abril") m=4 ; dia  ;;
"mayo") m=5 ; dia  ;;
"junio") m=6 ; dia  ;;
"julio") m=7 ; dia  ;;
"agosto") m=8 ; dia  ;;
"septiembre") m=9 ; dia  ;;
"octubre") m=10 ; dia  ;;
"noviembre") m=11 ; dia  ;;
"diciembre") m=12 ; dia  ;;
"Salir") exit 1;;
 *)
    echo "ERROR: Seleccione correctamente... "
    mes;;
esac
done
}

anno () {
echo " Seleccione la anno, insertando las dos ultimas cifras:"
read yshort

if [[ $( echo $yshort | sed 's/^[-+0-9][0-9]*//' | wc -c ) -ne 1 ]]; then echo "ERROR: Introduzca correctamente dos caracteres numericos." && exit 1; fi

if [[ $( expr length $yshort) -ne 2 ]] ; then echo "ERROR: Introduzca SOLO dos caracteres" && exit 1 ;fi
Y=20$yshort
}

fecha () {
fecha=`echo " $Y-$m-$d"`
echo $fecha
exit 0
}

main () {

anno
mes
dia

}

main

The problem? Simple, I want to select the day regarding the month, I mean, to print 30 days if you selected the month of 30 days and so on.

Any help on how to change my script?
Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find files on a given input date

Hello gurus, I need to write a script to find out all the file that got changed on a specific folder since a given input date (Date to be given as Input) Thanx (1 Reply)
Discussion started by: ar.karan
1 Replies

2. Shell Programming and Scripting

Help with Creation of Script to Input Separators in Data

Hi all, I have one problem that is preparing datas so I can run a script to extrat informations for my statistic reports. I receive some datas, that are informations mixed and I need to separate them to analyse. This is an exemple of datas:... (8 Replies)
Discussion started by: Alexis Duarte
8 Replies

3. Shell Programming and Scripting

problem piping input to script with echo

I am trying to have a script run without interaction from the command line. So in my script i have a line like this echo -e "\n\n\ny\ny\n" | ./script the goal being the ability to mimic 3 Enter presses and 2 'y/n' responses with 'y' followed by enter. For some reason tho, it is not... (1 Reply)
Discussion started by: mcdef
1 Replies

4. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

5. Shell Programming and Scripting

Script asks to input data

Hi, I have three different files about a warehouse's stock status. Each file shows storage locations, stored product names, quantity of the part and at last column, its price. When there is a change in price, I open those files one by one, search related product name at each row and change... (4 Replies)
Discussion started by: baris35
4 Replies

6. Shell Programming and Scripting

Input date on script

How can I allow users to change the date and time in a script? Say the user1 wil login and he will be inputting the desired date (example format below). I will need this script so the user can login and change the date anytime during the day. I will not allow him to use any command except the date... (2 Replies)
Discussion started by: lhareigh890
2 Replies

7. Shell Programming and Scripting

Script to get previous date for the given input date..

hi all, need a script or command to get the previous date for the given input date... like in my script i will pass date as input parameter like 2014-12-01 and i want the output as previous date.. ie.. 2014-11-30 (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

8. UNIX for Dummies Questions & Answers

UNIX shells script to echo out the date value

I appreciate if someone answer this question for my learning purpose: Given a filename structure of a COUNTRY CODE, file type, date (YYYYMMDD) and two digit attempt number with an extension of ".dat", write a UNIX shells script to echo out the date value. Example: ... (1 Reply)
Discussion started by: shumail
1 Replies

9. Shell Programming and Scripting

Variable input to awk script

Hi guys, I wrote the following function to compare two csv files column by column. However, sometimes the input needs to be sorted before parsing it to awk. I can do this by changing the awk arguments, but I would like to make this variable if possible. The below doesn't work since the... (3 Replies)
Discussion started by: Subbeh
3 Replies

10. Shell Programming and Scripting

Enhance existing script: Extract Multiple variables & Input in an echo string

Hi Experts I need your help to optimize my script to execute better as I have nearly 1M records & the script is taking close to 40 minutes to execute, so would need support on a faster alternative. Input: file {"house":"1024","zip":"2345","city":"asd","country":"zzv"}... (2 Replies)
Discussion started by: nk1984
2 Replies
LIBEXSLT(3)						     Library Functions Manual						       LIBEXSLT(3)

NAME
libexslt - extension library for XSLT SYNOPSIS
#include <libexslt/exslt.h> void exsltCommonRegister(void); void exsltDateRegister(void); void exsltDynRegister(void); void exsltFuncRegister(void); void exsltMathRegister(void); void exsltSetsRegister(void); void exsltStrRegister(void); void exsltRegisterAll(void); void exsltSaxonRegister(void); DESCRIPTION
The libexslt library is used to provide extensions to XSLT functions. These extensions come from the EXSLT project <http://www.exslt.org/> USAGE
To make use of these functions in XSLT the appropriate namespace must be defined on the xsl:stylesheet element. To enable support for them in libxslt(3) you must call the appropriate functions (listed in the SYNOPSIS section) to register the extensions. The xslt-config shell script can be used to obtain the necessary flags for the pre-processor and linker. The supported extensions are: COMMON Namespace: http://exslt.org/common See http://www.exslt.org/exsl/index.html for a description. node-set() convert the given RTF into a node-set. object-type() returns the type of the given argument. document Create multiple output documents. See http://www.exslt.org/exsl/elements/document/index.html MATH Namespace: http://exslt.org/math See http://www.exslt.org/math/index.html for a description. min() returns the minimum value of the given node-set max() returns the maximum value of the given node-set highest() returns the nodes in the node-set whose value is the maximum value for the node-set. lowest() returns the nodes in the node-set whose value is the minimum value for the node-set. constant() returns a number value of the given constant with the given precision. The constants are PI, E, SQRRT2, LN2, LN10, LOG2E, and SQRT1_2. random() returns a random number between 0 and 1 inclusive. abs() returns the absolute value of the argument. sqrt() returns the square root of the argument. power() returns the power base and power arguments. log() returns the natural log of the argument. sin() returns the sine of the argument. cos() returns the cosine of the argument. tan() returns the tangent of the argument. asin() returns the arc sine of the argument. acos() returns the arc cosine of the argument. atan() returns the arc tangent of the argument. atan2() returns the arc tangent function of the y/x arguments. exp() returns the exponential function of the argument. SETS Namespace: http://exslt.org/sets See http://www.exslt.org/set/index.html for a description. difference() returns the difference between the two given node-sets. intersection() returns a node-set of the nodes within both given node-sets. distinct() returns a node-set of all nodes in the first argument that are not in the seconds argument. has-same-node() returns TRUE if there is an intersection between the two given node-sets. leading() returns a node-set of all nodes in the first argument that precede the first node in the second argument. trailing() returns a node-set of all nodes in the first argument that follow the first node in the second argument. DATES and TIMES Namespace: http://exslt.org/dates-and-times See http://www.exslt.org/date/date.html for a description. date-time() returns the current date and time as a date/time string. date() returns the date specified in the given date/time string. time() returns the time specified in the date/time string given as the argument. year() returns the year of a date as a number. leap-year() returns true if the year given in a date is a leap year. month-in-year() returns the month of a date as a number. month-name() returns the full name of the month of a date. month-abbreviation() returns the abbreviation of the month of a date. week-in-year() returns the week of the year as a number. week-in-month() returns the week in a month of a date as a number. day-in-year() returns the month of a date as a number. day-in-month() returns the day of a date as a number. day-of-week-in-month() returns the day-of-the-week in a month of a date as a number. day-in-week() returns the day of the week given in a date as a number. day-name() returns the full name of the day of the week of a date. day-abbreviation() returns the abbreviation of the day of the week of a date. hour-in-day() returns the hour of the day as a number. minute-in-hour() returns the minute of the hour as a number. second-in-minute() returns the second of the minute as a number. seconds() returns the number of seconds specified by the argument string. add() returns the date/time resulting from adding a duration to a date/time. add-duration() returns the duration resulting from adding two given durations together. difference() returns the duration between the first date and the second date. duration() returns a duration string that represents the given number of seconds since 1970-01-01T00:00:00. STRINGS Namespace: http://exslt.org/strings See http://www.exslt.org/str/index.html for a description. tokenize() returns a node set of token elements, each containing one token from the string. padding() returns a string padded to a certain length. align() returns a string aligned within another string. concat() returns the concatenation of the string values of the nodes in that node set. FUNCTIONS Namespace: http://exslt.org/functions See http://www.exslt.org/func/index.html for a description. function declares an extension function. result returns the result of an extension function declared in function(). FILES
/usr/bin/xslt-config shell script giving pre-processor and linker flags. /usr/lib/libexslt.a static library /usr/lib/libexslt.so sharable library AUTHORS
Manual page by Heiko W. Rupp (hwr@pilhuhn.de) SEE ALSO
libxml(3), libxslt(3), xmllint(1) xsltproc(1), libxslt 04 November 2003 LIBEXSLT(3)
All times are GMT -4. The time now is 03:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy