在linux中使用.sh文件将csv文件数据传递到命令

在linux中使用.sh文件将csv文件数据传递到命令,linux,Linux,我想将我的n号csv数据传递到命令“esusers useradd username-r role-p password”中。如何在linux机器上执行此操作。我已经做了这个窗口,但无法在linux机器上做任何人可以帮我走出这个困境。我的输入也将包含标题。csv文件user.csv: user1,role1,pass1 user2,role2,pass2 user3,role3,pass3 #!/bin/bash # Check parameters if [ "$#" -ne 1 ]; t

我想将我的n号csv数据传递到命令“esusers useradd username-r role-p password”中。如何在linux机器上执行此操作。我已经做了这个窗口,但无法在linux机器上做任何人可以帮我走出这个困境。我的输入也将包含标题。

csv文件user.csv

user1,role1,pass1
user2,role2,pass2
user3,role3,pass3
#!/bin/bash

# Check parameters
if [ "$#" -ne 1 ]; then
     >&2 echo "Illegal number of parameters"
    exit 1
fi

# Check file
if [ ! -f "${1}" ]; then
     >&2 echo "File ${1} not found"
    exit 1
fi

FILE="${1}"

while read line; do
    USER=`echo ${line} | cut -d"," -f1`
    ROLE=`echo ${line} | cut -d"," -f2`
    PASS=`echo ${line} | cut -d"," -f3`

    echo "adding user ${USER} (role: ${ROLE}) with password: ${PASS}"
    esusers useradd "${USER}" -r "${ROLE}" -p "${PASS}"
done < ${FILE}
迭代csv文件的bash脚本(scripts.sh)

user1,role1,pass1
user2,role2,pass2
user3,role3,pass3
#!/bin/bash

# Check parameters
if [ "$#" -ne 1 ]; then
     >&2 echo "Illegal number of parameters"
    exit 1
fi

# Check file
if [ ! -f "${1}" ]; then
     >&2 echo "File ${1} not found"
    exit 1
fi

FILE="${1}"

while read line; do
    USER=`echo ${line} | cut -d"," -f1`
    ROLE=`echo ${line} | cut -d"," -f2`
    PASS=`echo ${line} | cut -d"," -f3`

    echo "adding user ${USER} (role: ${ROLE}) with password: ${PASS}"
    esusers useradd "${USER}" -r "${ROLE}" -p "${PASS}"
done < ${FILE}