系统日期变为unix

BKK*_*BKK 4 unix date sh

我想运行以下脚本

#!/bin/sh
temp =`date +%Y%m%d`
echo "$temp"
Run Code Online (Sandbox Code Playgroud)

但是这没有按预期运行它会抛出这个错误消息temp:执行权限被拒绝

fed*_*qui 8

你有

temp =`date +%Y%m%d`
    ^
Run Code Online (Sandbox Code Playgroud)

所以,你需要删除之间的空间tempdate:

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

有了它,它对我有用.

确保该文件具有执行权限:

chmod +x your_file
Run Code Online (Sandbox Code Playgroud)

或者只是执行它

/bin/sh /your/script/path/your_file
Run Code Online (Sandbox Code Playgroud)