繁体   English   中英

linux脚本文件检查是否这是最后添加的用户

[英]linux scripting file check if this the last added user

我想说他不是创建的最后一个用户。 或者他是创建的最后一个用户。

这是我创建的脚本:

#!/bin/bash
$laatst = $(cut -d: -f1 /etc/passwd)
$laatste= $(tail -1 $laatst)

if [ $user = $laatste]
then echo "i am $user and i am created at last"
else echo "i am $user and i am not created as last"
echo "the last created user is $laatste"
fi

错误:./ lastuser.sh:第5行:= root:找不到命令

有谁知道为什么它没有得到最后添加的用户名和其他错误?

'='之前或之后没有空格。 同样,在设置变量时,变量前面没有美元符号。

另外,字符串的求值就是您要查找的内容,这就是应用于tail命令的内容。

您的支票是否需要空格。

我看不到$ user曾经初始化过任何东西。

#!/bin/bash

laatst='cut -d: -f1 /etc/passwd'
laatste=$($laatst | tail -1)
if [[ $user == $laatste ]]
then echo "i am $user and i am created at last"
else 
    echo "i am $user and i am not created as last"
    echo "the last created user is $laatste"
fi

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM