You are not logged in.
Hi! im trying to make an script to change the date/time in my flux system... using the date command and entering the new date time manually and then the script use that to pass them to the date command, here's what i got now (dont laught too loud ), but dont know how to pass the variables to the date command:
#!/bin/bash
echo This script changes system date
echo New Date: (mmdd):
read date
echo Year (yyyy):
read year
echo Time (hhmm):
read time
# -- command that set's new date --
date datetimeyear # <---- the date command takes this format as valid mmddhhmmyyyy
echo System date modified successfully
echo --- Press a key to exit ---
read
Last edited by leo2501 (2008-01-06 16:57:49)
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline
Dollars is what you want, $date$time$year will do.
Offline
you need to put quotes around the New Date.... types of lines because of the parens. Bash needs to know that these are strings. also when reading in a variable you just use the var name, but when referencing the variable use $varname, so the line would be "date $date$time$year". also the time variable needs a different name as time is already a keyword. for reference,
#!/bin/bash
echo This script changes system date
echo "New Date: (mmdd):"
read date
echo "Year (yyyy):"
read year
echo "Time (hhmm):"
read ttime
# -- command that set's new date --
date $date$ttime$year # <---- the date command takes this format as valid mmddhhmmyyyy
echo System date modified successfully
echo --- Press a key to exit ---
read
is what i changed it to, it works, but coding practices probably need some work. it's nice to see you are learning scripts to make your life easier. many people just rely on scripts other people wrote to do things for them.
edit: how did i miss the post above me??
Last edited by rson451 (2008-01-06 16:49:56)
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
Thank u all!!! i love learning to do everything my way that way i do it the way i like and dont the way others like
i forget to add the "sudo" command to the date command:
sudo date $date$ttime$year # <---- the date command takes this format as valid mmddhhmmyyyy
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery
Offline
Some handy reference guides for scripting can be found at TLDP.org
I always look back at the Advanced Guide when I'm unsure about something.. it's very helpful.
Offline