小编slo*_*oow的帖子

Bash:警告:here-document在由文件结尾分隔的行(想要'EOF')

bash中的以下函数会出现标题中提到的错误.当最终EOF不在行的开头时,通常会出现错误.

EOF是在开始,所以我看不出有什么问题.进一步在脚本(未显示)中还有其他here-docs,它们可以工作.

add_testuser()
{
    kadmin -p admin -q addprinc test
    cat <<EOF > ~/test.ldif
dn: cn=test,ou=groups,dc=${ARRAY[1]},dc=${ARRAY[2]}
cn: test
gidNumber: 20001
objectClass: top
objectClass: posixGroup

dn: uid=test,ou=people,dc=${ARRAY[1]},dc=${ARRAY[2]}
uid: test
uidNumber: 20001
gidNumber: 20001
cn: First_name
sn: Last_name
objectClass: top
objectClass: person
objectClass: posixAccount
objectClass: shadowAccount
loginShell: /bin/bash
homeDirectory: /home/test
userPassword: {CRYPT}*
EOF 

    ldapadd -Qf ~/test.ldif
    kdestroy; kinit test
    klist
    ldapwhoami
}
Run Code Online (Sandbox Code Playgroud)

bash heredoc eof

6
推荐指数
1
解决办法
2万
查看次数

PostgreSQL:忽略左外部自连接的更新

我想更新的列leaf_categoryTRUE其中的类别是不是一个父类.它作为一个select语句:

 select 
     c1.id, c1.name, c1.slug, c1.level, c2.parent_id, c2.name, c2.slug, c2.level 
 from
     catalog_category c1 
 left outer join 
     catalog_category c2 on 
     (c1.id = c2.parent_id)
 where 
     c2.parent_id is null;
Run Code Online (Sandbox Code Playgroud)

但是,相应的UPDATE设置所有列TRUE.

update catalog_category 
set leaf_category = True
from
    catalog_category c1 
left outer join 
    catalog_category c2 on 
    (c1.id = c2.parent_id)
 where 
     c2.parent_id is null;
Run Code Online (Sandbox Code Playgroud)

UPDATE这样的可能呢?

sql postgresql join sql-update

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

python dict.fromkeys()返回空

我写了以下函数.它不应该返回一个空字典.代码在没有功能的命令行上工作.但是我看不出这个功能有什么问题,所以我必须诉诸你的集体智慧.

def enter_users_into_dict(userlist):
    newusr = {}
    newusr.fromkeys(userlist, 0)
    return newusr

ul = ['john', 'mabel']
nd = enter_users_into_dict(ul)
print nd
Run Code Online (Sandbox Code Playgroud)

它返回一个空的dict {},我希望{'john':0,'mabel':0}.

它可能非常简单,但我没有看到解决方案.

python dictionary fromkeys

2
推荐指数
1
解决办法
1714
查看次数

标签 统计

bash ×1

dictionary ×1

eof ×1

fromkeys ×1

heredoc ×1

join ×1

postgresql ×1

python ×1

sql ×1

sql-update ×1