system date into variable unix system date into variable unix unix unix

system date into variable unix


You have

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

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

#!/bin/shtemp=$(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


temp variable needs to be assigned without spaces.


Your script indeed has a syntax error, to fix it remove the space after temp in the second line, but this error will not throw execute permission denied but line 2: temp: command not found.

Your script does not have the execution rights, to fix it invoke:

chmod +x FILE.sh

where FILE is the name of this script.