Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

system date into variable unix

Tags:

date

unix

sh

I want to run the following script

#!/bin/sh
temp =`date +%Y%m%d`
echo "$temp"

But this not running as expected it is throwing this error message temp: execute permission denied

like image 232
BKK Avatar asked Feb 16 '23 10:02

BKK


1 Answers

You have

temp =`date +%Y%m%d`
    ^

So you need to remove the space between temp and date:

#!/bin/sh
temp=$(date +%Y%m%d) # better than `exp`, thanks @OliverDulac (see comments)
echo "$temp"

With this it works to me.

Make sure the file has execution permissions:

chmod +x your_file

or just execute it with

/bin/sh /your/script/path/your_file
like image 155
fedorqui 'SO stop harming' Avatar answered Feb 24 '23 14:02

fedorqui 'SO stop harming'