Logo Questions Linux Laravel Mysql Ubuntu Git Menu

system date into variable unix





I want to run the following script

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


1 Answers

You have

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

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

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'