I am new to bash script programming.
I want to implement a bash script 'deploymLog', which accepts as input one string argument(name).
[root@localhost Desktop]# ./deploymLog.sh name
here I want to pass the string argument(name) through command line
As an initial step, I need to append the current timestamp along with this input string to a log file say Logone.txt
in current directory in the below format:
[name]=[System time timestamp1]
How it is possible?
Best Answer
The first argument from a command line can be found with the positional parameter
$1
.[[ -n "$name" ]]
tests to see if$name
is not empty.date +%s
returns the current timestamp in Unix time. The>>
operator is used to write to a file by appending to the existing data in the file.For more readable timestamp you could play with
date
arguments.