I am trying to create a script that will take epoch (input from command line) and convert it into a readable format in bash/shell
---------- Post updated at 08:03 PM ---------- Previous update was at 07:59 PM ----------
#!bin/bash
read -p "Please enter a number to represent epoch time:" STRING
echo "The UNIX time for $STRING is ($(($date -d "$STRING" + %m-%d-%Y %T utc)"
When I ran the code with the @ symbol - it returns
date: invalid date '@String'
should I rename STRING to something else? or am I missing a parameter with this code? I took a scripting class but it was years ago and I cannot find anything online.
#!/bin/bash
read -p "Please enter a number to represent epoch time:" STRING
echo "The UNIX time for $STRING is (date -d@$"STRING" +%m-%d-%Y %T -utc)"
Output: Please enter a number to represent epoch time:34565444
The UNIX time for 34565444 is (date -d@$STRING +%m-%d-%Y %T -utc)
I did that but still received the same output, so:
I tried this:
#!/bin/bash
read -p "Please enter a number to represent epoch time:" STRING
echo "The UNIX time for $STRING is:" $($((date -d@"$STRING" +%m-%d-%Y %T -utc)))
The output was:
Please enter a number to represent epoch time:3456543
./test1.bash: line 4: date -d@"3456543" +%m-%d-%Y %T -utc: syntax error: invalid arithmetic operator (error token is "@"3456543" +%m-%d-%Y %T -utc")
The UNIX time for 3456543 is: