Shell script to prompt for input
Hi,
I would like to run some existing scripts and send it to a text file: Note: 'script' is an exist shell script Note: '/opt/2011jun15/my.db' auto generates everyday with only changes to the directory 2011jun15 base on the current date currently i will need to run the script manually and make changes to the path below, change directory name 2011jun15 daily and text file new2011jun15.txt ./script -f /opt/2011jun15/my.db > new2011jun15.txt Am i able to write a shell script to prompt me for a change of path for only '2011jun15' and 'new2011jun15.txt'? It will be great if i can automate the whole process? Thanks in advanced. |
Yes ... have a look at your favourite documentation and look for command line parameters (they look like - $1, $2 ...)
|
Quote:
./script -f /opt/2011jun15/my.db > new2011jun15.txt |
You can retrieve the current date using the date command and put it in the format you want (except you have to translate the uppercase month to lowercase), e.g.
Code:
./script -f /opt/$(date +%Y%b%d | tr [A-Z] [a-z])/my.db > new$(date +%Y%b%d | tr [A-Z] [a-z]).txt |
So I am not sure if colucix's answer is what you are after or are you just asking how to change entry A with entry B?
So to use your example, do you no longer wish to call the script with -f and now just enter the new portion of the path so it is read that way in the script? For example: Code:
./script 2011jun16 If so, inside 'script' you can have: Code:
if (( $# != 1 )) |
Quote:
|
Quote:
|
I am trying another option to input the date manually.
I need the input to be in title case, for example if i enter 2011jun23 it will read it as 2011Jun23. This is to ensure that the path is /opt/2011Jun23/my.db #!/bin/bash echo "Enter the date" read i ./script -f /opt/$1/my.db > new$1.txt |
So is there a question or you are just informing us of your choice?
|
Quote:
|
Well with a little playing the not so intuitive answer is, you have to alter (if I am wrong hopefully someone will say)
the input to get the desired output: Code:
#!/bin/bash Code:
./new_script.sh 06jun2011 I think it would still be easier to include this testing / input in your original script. |
Quote:
Some mistakes in my previous script, it is suppose to be $i instead of $1, btw I would like to have the option to enter the date I want and would want to ensure that it turns out to be the correct format I want eg.. 2011Jun23 (Title case for Jun), Thanks |
All times are GMT -5. The time now is 08:27 PM. |