我在.sh文件中编写代码并运行它...
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 2 ] || die "2 argument required, $# provided"
echo $2 | grep -E -q '^[0-9]+$' || die "Numeric argument required, $2 provided"
nfile_location = /home/virtual/$1
if [ -f $nfile_location ];
then
chmod -R $2 $nfile_location
echo "Set permission";
exit 1;
else
echo "Not a correct file";
exit 1;
fi
Run Code Online (Sandbox Code Playgroud)
但它不起作用.它显示以下错误,我无法理解,因为我是bash脚本的新手.
/root/new_scripts/setpermission.sh: line 11: nfile_location: command not found
chmod: missing operand after `777'
Try `chmod --help' for more information.
Set permission
Run Code Online (Sandbox Code Playgroud)
在=标志之前或之后必须没有空格.
错误: nfile_location = /home/virtual/$1
正确: nfile_location=/home/virtual/$1
| 归档时间: |
|
| 查看次数: |
1354 次 |
| 最近记录: |