Skip to content

Instantly share code, notes, and snippets.

@oppara
Created January 26, 2020 04:08
Show Gist options
  • Save oppara/d677f3da14bcac4b06e88d067a3fc59a to your computer and use it in GitHub Desktop.
Save oppara/d677f3da14bcac4b06e88d067a3fc59a to your computer and use it in GitHub Desktop.
shell script loop pipe while read
#!/bin/bash
set -eu
users() {
# user password
cat << EOF
foo foofoo
bar barbar
baz bazbaz
EOF
}
create_user() {
while read user pw line
do
echo "create user ${user}"
useradd -g devel ${user}
echo "umask 002" >> /home/${user}/.bashrc
echo ${pw} | passwd --stdin ${user}
done
}
users | create_user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment