击:参数太多 [英] Bash: Too many arguments

查看:117
本文介绍了击:参数太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有codeD以下脚本从文本文件添加用户。它的工作原理,但我发现了,说:太多的参数的错误;问题究竟是什么?

 #!/斌/庆典文件= users.csv而IFS =,读USRNM DOB SCH PRG PST ENROLSTAT;做如果[$ ENROLSTAT ==完成];
然后
useradd的$ USRNM -p $ DOB其他回声用户$ USRNM没有完全纳入
科幻完成< $文件#cat users.csv |头-n 2 |尾-n 1


解决方案

使用引号。从优。

 如果[$ ENROLSTAT=完成]

(这是一个等号了。)我在shell编程最大的问题总是隐藏空间。这是我写了这么多在Perl的原因之一,为什么呢,在Perl中,我告诉大家对我的团队的避免了外壳的运行时外部程序。只是有那么大的力量在外壳,有这么多的小事情,可你绊倒,我尽可能避免使用。 (而不是哪里不可能的。)

I've coded the following script to add users from a text file. It works, but I'm getting an error that says "too many arguments"; what is the problem?

#!/bin/bash

file=users.csv

while IFS="," read USRNM DOB SCH PRG PST ENROLSTAT ; do

if [ $ENROLSTAT == Complete ] ;
then
useradd $USRNM -p $DOB

else

echo "User $USRNM is not fully enrolled"
fi

done < $file

#cat users.csv | head -n 2 | tail -n 1

解决方案

Use quotes. Liberally.

if [ "$ENROLSTAT" = Complete ]

(It's a single equal sign, too.) My greatest problem in shell programming is always hidden spaces. It's one of the reasons I write so much in Perl, and why, in Perl, I tell everyone on my team to avoid the shell whenever running external programs. There is just so much power in the shell, with so many little things that can trip you up, that I avoid it where possible. (And not where not possible.)

这篇关于击:参数太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆