Ubuntu系统登录一个用户时,报错cannot possibly work without effective root
时间: 2024-04-12 11:31:52 浏览: 11
这个错误通常是由于用户在无效的权限下尝试执行需要管理员权限的操作引起的。在Ubuntu系统中,只有root用户或具有sudo权限的用户才能执行这些操作。请确保你正在使用具有sudo权限的用户账户登录,并正确输入密码。
如果你不确定是否具有sudo权限,请尝试使用以下命令查看当前用户的权限:
```
sudo -l
```
如果你的用户有sudo权限,那么你应该看到一条包含"Matching Defaults entries for <username> on <hostname>:"的消息。
如果你没有sudo权限,你需要切换到具有sudo权限的用户账户,或联系系统管理员来获取相应的权限。
相关问题
python中的报错is possibly unbound
在python中,“可能未绑定”(possibly unbound)的错误通常是指尝试使用未初始化或未赋值的变量。这种错误可以在代码中任何地方发生,而不仅仅是在变量的定义处。
例如,以下代码中的变量x是“可能未绑定”的:
```python
def func():
if some_condition:
x = 10
print(x)
```
在这个例子中,如果some_condition不成立,则x将没有被初始化并且在打印时会引发一个可能未绑定的错误。
为了避免这种错误,应该在使用变量之前始终将其初始化或赋值。一个简单的方法是在变量的定义处将其初始化为None,这将确保它始终是已绑定的:
```python
def func():
x = None
if some_condition:
x = 10
print(x)
```
这个例子中,即使some_condition不成立,x仍然会被初始化为None,因此打印语句不会发生可能未绑定的错误。
写一个C语言实现简单词法分析器
好的,以下是一个简单的C语言词法分析器的示例代码:
```
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAXTOKEN 100
enum {NAME, PARENS, BRACKETS};
void dcl(void);
void dirdcl(void);
int gettoken(void);
int tokentype;
char token[MAXTOKEN];
char name[MAXTOKEN];
char datatype[MAXTOKEN];
char out[1000];
int main()
{
while (gettoken() != EOF) {
strcpy(datatype, token);
out[0] = '\0';
dcl();
if (tokentype != '\n')
printf("syntax error\n");
printf("%s: %s %s\n", name, out, datatype);
}
return 0;
}
void dcl(void)
{
int ns;
for (ns = 0; gettoken() == '*'; ) /* count *'s */
ns++;
dirdcl();
while (ns-- > 0)
strcat(out, " pointer to");
}
void dirdcl(void)
{
int type;
if (tokentype == '(') {
dcl();
if (tokentype != ')')
printf("error: missing )\n");
} else if (tokentype == NAME)
strcpy(name, token);
else
printf("error: expected name or (dcl)\n");
while ((type=gettoken()) == PARENS || type == BRACKETS)
if (type == PARENS)
strcat(out, " function returning");
else {
strcat(out, " array");
strcat(out, token);
strcat(out, " of");
}
}
int gettoken(void)
{
int c, getch(void);
void ungetch(int);
char *p = token;
while ((c = getch()) == ' ' || c == '\t')
;
if (c == '(') {
if ((c = getch()) == ')') {
strcpy(token, "()");
return tokentype = PARENS;
} else {
ungetch(c);
return tokentype = '(';
}
} else if (c == '[') {
for (*p++ = c; (*p++ = getch()) != ']'; )
;
*p = '\0';
return tokentype = BRACKETS;
} else if (isalpha(c)) {
for (*p++ = c; isalnum(c = getch()); )
*p++ = c;
*p = '\0';
ungetch(c);
return tokentype = NAME;
} else
return tokentype = c;
}
#define BUFSIZE 100
char buf[BUFSIZE]; /* buffer for ungetch */
int bufp = 0; /* next free position in buf */
int getch(void) /* get a (possibly pushed-back) character */
{
return (bufp > 0) ? buf[--bufp] : getchar();
}
void ungetch(int c) /* push character back on input */
{
if (bufp >= BUFSIZE)
printf("ungetch: too many characters\n");
else
buf[bufp++] = c;
}
```
这个程序实现了一个简单的C语言词法分析器,可以识别以*、()、[]等方式定义的函数、指针、数组等类型。您可以尝试输入一些示例代码进行测试。