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
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
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
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.
In sh scripts (not just bash) the equal sign is not accepted when assigning a variable, because you could do something like this:
VARIABLE=something ./runcommand
to have that variable exported to the ./runcommand subprocess but not in general exported to all subprocesses.
If space were allowed there would be no way to distinguish the end of the assignment with the start of the command line.
I found the mistake in my above code, i allowed a space after the string temp
. that is causing the error.