我有脚本将结构从.txt文件更改为“ newusers”命令可读结构,该结构非常适合1个文件,但这意味着我每次需要在新文件中使用该脚本时都必须编辑该脚本。我已经读过关于位置参数的信息,我认为这是我在这种情况下所需要的,但是不确定如何应用该参数来实现我的目标。
在执行脚本时我该怎么做以传递参数,以便它可以处理每个文件而无需进一步/每次编辑脚本?
到目前为止,我的脚本可以使用 bash script.sh ,没有参数。
到目前为止的代码:
#!/bin/bash
clear
while IFS=: read -r userid username group; do
if [ "$group" = "group1" ]; then
groupid=2020
elif [ "$group" = "group2" ]; then
groupid=2040
else
echo "Unknown group"
fi
echo "$userid:password123::$groupid:$username:/home/$userid/bin/bash";
done #< users2.txt > newusers2.txt
预期结果:
bash script.sh oldfile1 newfile1
干杯。