小编tri*_*lef的帖子

使用命令禁用 linux 用户的密码

基于第二个(密码)字段的/etc/shadow(5)文档

加密密码

如果密码字段包含一些不是 crypt(3) 的有效结果的字符串,例如!或*,用户将无法使用unix密码登录(但用户可以通过其他方式登录系统)。

我的问题是是否有禁用用户密码的 linux 命令,即设置“*”或“!” 在密码字段上。

linux security password shadow

7
推荐指数
1
解决办法
6611
查看次数

Bash 文件存在测试始终为真

我有以下 bash 脚本行来测试文件是否存在:

MYAPPPATH=$(find $APPDIR -iname myapp* -print)
if [ -e $MYAPPPATH ]
then
    echo "File exists" 
fi
Run Code Online (Sandbox Code Playgroud)

但是,当以“myapp”开头的文件不存在时,因此 MYAPPPATH='',上述检查再次成功。看看使用时会发生什么set -x,但文件不存在:

++ find /path/to/app -iname 'myapp*' -print
+ MYAPPPATH=
+ '[' -e ']'
+ echo 'File exists'
Run Code Online (Sandbox Code Playgroud)

这是什么原因?

我需要做什么才能使这项工作按预期进行?

shell bash shell-script quoting test

5
推荐指数
2
解决办法
5683
查看次数

getopts 似乎不起作用

我正在尝试运行以下脚本getopts来解析选项,但它似乎不起作用:

#!/bin/bash
set -x
echo $@
while getopts "rf" opt
do
  case "${opt}" in
    r)
        ropt=${OPTARG}
        ;;
    f)
        fopt=${OPTARG}
        ;;
  esac
done

shift $((OPTIND -1))

echo $fopt $ropt
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

$ ./myscript.sh -f opt2 -r opt1
+ echo -f opt2 -r opt1
-f opt2 -r opt1
+ getopts rf opt
+ case "${opt}" in
+ fopt=
+ getopts rf opt
+ shift 1
+ echo

+ set +x
Run Code Online (Sandbox Code Playgroud)

你对我做错了什么有任何想法吗?

bash getopts

3
推荐指数
1
解决办法
2465
查看次数

标签 统计

bash ×2

getopts ×1

linux ×1

password ×1

quoting ×1

security ×1

shadow ×1

shell ×1

shell-script ×1

test ×1