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

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

问题描述

我编写了以下脚本以从文本文件添加用户.它有效,但我收到一个错误,提示参数太多";有什么问题?

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

推荐答案

使用引号.自由自在.

if [ "$ENROLSTAT" = Complete ]

(它也是一个等号.)我在 shell 编程中最大的问题总是隐藏空间.这是我用 Perl 写这么多的原因之一,也是为什么在 Perl 中,我告诉团队中的每个人在运行外部程序时避免使用 shell.外壳中的力量如此之大,有如此多的小事情会让你绊倒,所以我尽可能避免使用它.(而不是在不可能的地方.)

(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.)

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

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