An option is not seeing an argument (that is a variable) in bash, please help?
up vote
1
down vote
favorite
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
psswd= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2
full_name= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3
group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4
second_group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5
sudo useradd $username -m -g $group -s /bin/bash -c $full_name
if [ second_group = LPGestionnaires ]
then
usermod -a -G $second_group $user
fi
#echo "$username:$psswd" | chpasswd
((counter++))
done
echo Execution complete
The part where it says sudo useradd $username -m -g $group -s /bin/bash -c $full_name
is the part that isn't working, my -g option isn't seeing the variable $group argument as an argument, when I execute my script it returns this: useradd: group '-s' does not exist
I'm pulling the data from a .csv file that is located correctly.
If anyone could help that would be great!
Thanks!
command-line bash scripts
New contributor
add a comment |
up vote
1
down vote
favorite
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
psswd= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2
full_name= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3
group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4
second_group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5
sudo useradd $username -m -g $group -s /bin/bash -c $full_name
if [ second_group = LPGestionnaires ]
then
usermod -a -G $second_group $user
fi
#echo "$username:$psswd" | chpasswd
((counter++))
done
echo Execution complete
The part where it says sudo useradd $username -m -g $group -s /bin/bash -c $full_name
is the part that isn't working, my -g option isn't seeing the variable $group argument as an argument, when I execute my script it returns this: useradd: group '-s' does not exist
I'm pulling the data from a .csv file that is located correctly.
If anyone could help that would be great!
Thanks!
command-line bash scripts
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
psswd= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2
full_name= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3
group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4
second_group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5
sudo useradd $username -m -g $group -s /bin/bash -c $full_name
if [ second_group = LPGestionnaires ]
then
usermod -a -G $second_group $user
fi
#echo "$username:$psswd" | chpasswd
((counter++))
done
echo Execution complete
The part where it says sudo useradd $username -m -g $group -s /bin/bash -c $full_name
is the part that isn't working, my -g option isn't seeing the variable $group argument as an argument, when I execute my script it returns this: useradd: group '-s' does not exist
I'm pulling the data from a .csv file that is located correctly.
If anyone could help that would be great!
Thanks!
command-line bash scripts
New contributor
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
psswd= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2
full_name= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3
group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4
second_group= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5
sudo useradd $username -m -g $group -s /bin/bash -c $full_name
if [ second_group = LPGestionnaires ]
then
usermod -a -G $second_group $user
fi
#echo "$username:$psswd" | chpasswd
((counter++))
done
echo Execution complete
The part where it says sudo useradd $username -m -g $group -s /bin/bash -c $full_name
is the part that isn't working, my -g option isn't seeing the variable $group argument as an argument, when I execute my script it returns this: useradd: group '-s' does not exist
I'm pulling the data from a .csv file that is located correctly.
If anyone could help that would be great!
Thanks!
command-line bash scripts
command-line bash scripts
New contributor
New contributor
edited 14 mins ago
wjandrea
8,07242258
8,07242258
New contributor
asked 1 hour ago
moltenmath
83
83
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
It seems you wanted to assign the result of the head ...
command to the variable username
here:
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
That is incorrect syntax. Correct it like this:
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
And then do the same for the other variables too, which all have the same problem.
Also, change the sudo useradd
command like this:
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
Variables used in command line arguments should usually be double-quoted to avoid word splitting.
Thanks for the help! It now returns the man page for useradd for some reason...
– moltenmath
1 hour ago
@moltenmath change thesudo
command like this:sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
. I suspect it won't work either, but we will get a more meaningful error output.
– janos
1 hour ago
Edit: Nevermind, none of the users were added to groups
– moltenmath
1 hour ago
1
@moltenmath add anecho
statement to see better what's happening, for exampleecho sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
– janos
53 mins ago
Thanks for all the help @janos this thread can now be closed, is that a thing here?
– moltenmath
30 mins ago
|
show 1 more comment
up vote
0
down vote
The final code is this for anyone that is curious:
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
psswd=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2)
full_name=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3)
group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4)
second_group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5)
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
if [ "$second_group" = LPGestionnaires ]
then
sudo usermod -a -G LPGestionnaires "$username"
fi
echo "$username:$psswd" | sudo chpasswd
((counter++))
done
echo Execution complete
New contributor
You're almost re-inventing thenewusers
command here - at the very least, your script could be made somewhat neater by using awhile
loop (something likewhile IFS=';' read -r username passwd full_name group second_group; do stuff; done < ./user_sheet.csv
)
– steeldriver
1 min ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
moltenmath is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1102437%2fan-option-is-not-seeing-an-argument-that-is-a-variable-in-bash-please-help%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
It seems you wanted to assign the result of the head ...
command to the variable username
here:
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
That is incorrect syntax. Correct it like this:
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
And then do the same for the other variables too, which all have the same problem.
Also, change the sudo useradd
command like this:
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
Variables used in command line arguments should usually be double-quoted to avoid word splitting.
Thanks for the help! It now returns the man page for useradd for some reason...
– moltenmath
1 hour ago
@moltenmath change thesudo
command like this:sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
. I suspect it won't work either, but we will get a more meaningful error output.
– janos
1 hour ago
Edit: Nevermind, none of the users were added to groups
– moltenmath
1 hour ago
1
@moltenmath add anecho
statement to see better what's happening, for exampleecho sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
– janos
53 mins ago
Thanks for all the help @janos this thread can now be closed, is that a thing here?
– moltenmath
30 mins ago
|
show 1 more comment
up vote
3
down vote
accepted
It seems you wanted to assign the result of the head ...
command to the variable username
here:
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
That is incorrect syntax. Correct it like this:
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
And then do the same for the other variables too, which all have the same problem.
Also, change the sudo useradd
command like this:
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
Variables used in command line arguments should usually be double-quoted to avoid word splitting.
Thanks for the help! It now returns the man page for useradd for some reason...
– moltenmath
1 hour ago
@moltenmath change thesudo
command like this:sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
. I suspect it won't work either, but we will get a more meaningful error output.
– janos
1 hour ago
Edit: Nevermind, none of the users were added to groups
– moltenmath
1 hour ago
1
@moltenmath add anecho
statement to see better what's happening, for exampleecho sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
– janos
53 mins ago
Thanks for all the help @janos this thread can now be closed, is that a thing here?
– moltenmath
30 mins ago
|
show 1 more comment
up vote
3
down vote
accepted
up vote
3
down vote
accepted
It seems you wanted to assign the result of the head ...
command to the variable username
here:
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
That is incorrect syntax. Correct it like this:
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
And then do the same for the other variables too, which all have the same problem.
Also, change the sudo useradd
command like this:
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
Variables used in command line arguments should usually be double-quoted to avoid word splitting.
It seems you wanted to assign the result of the head ...
command to the variable username
here:
username= head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1
That is incorrect syntax. Correct it like this:
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
And then do the same for the other variables too, which all have the same problem.
Also, change the sudo useradd
command like this:
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
Variables used in command line arguments should usually be double-quoted to avoid word splitting.
edited 1 hour ago
answered 1 hour ago
janos
3,7061445
3,7061445
Thanks for the help! It now returns the man page for useradd for some reason...
– moltenmath
1 hour ago
@moltenmath change thesudo
command like this:sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
. I suspect it won't work either, but we will get a more meaningful error output.
– janos
1 hour ago
Edit: Nevermind, none of the users were added to groups
– moltenmath
1 hour ago
1
@moltenmath add anecho
statement to see better what's happening, for exampleecho sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
– janos
53 mins ago
Thanks for all the help @janos this thread can now be closed, is that a thing here?
– moltenmath
30 mins ago
|
show 1 more comment
Thanks for the help! It now returns the man page for useradd for some reason...
– moltenmath
1 hour ago
@moltenmath change thesudo
command like this:sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
. I suspect it won't work either, but we will get a more meaningful error output.
– janos
1 hour ago
Edit: Nevermind, none of the users were added to groups
– moltenmath
1 hour ago
1
@moltenmath add anecho
statement to see better what's happening, for exampleecho sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
– janos
53 mins ago
Thanks for all the help @janos this thread can now be closed, is that a thing here?
– moltenmath
30 mins ago
Thanks for the help! It now returns the man page for useradd for some reason...
– moltenmath
1 hour ago
Thanks for the help! It now returns the man page for useradd for some reason...
– moltenmath
1 hour ago
@moltenmath change the
sudo
command like this: sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
. I suspect it won't work either, but we will get a more meaningful error output.– janos
1 hour ago
@moltenmath change the
sudo
command like this: sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
. I suspect it won't work either, but we will get a more meaningful error output.– janos
1 hour ago
Edit: Nevermind, none of the users were added to groups
– moltenmath
1 hour ago
Edit: Nevermind, none of the users were added to groups
– moltenmath
1 hour ago
1
1
@moltenmath add an
echo
statement to see better what's happening, for example echo sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
– janos
53 mins ago
@moltenmath add an
echo
statement to see better what's happening, for example echo sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
– janos
53 mins ago
Thanks for all the help @janos this thread can now be closed, is that a thing here?
– moltenmath
30 mins ago
Thanks for all the help @janos this thread can now be closed, is that a thing here?
– moltenmath
30 mins ago
|
show 1 more comment
up vote
0
down vote
The final code is this for anyone that is curious:
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
psswd=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2)
full_name=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3)
group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4)
second_group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5)
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
if [ "$second_group" = LPGestionnaires ]
then
sudo usermod -a -G LPGestionnaires "$username"
fi
echo "$username:$psswd" | sudo chpasswd
((counter++))
done
echo Execution complete
New contributor
You're almost re-inventing thenewusers
command here - at the very least, your script could be made somewhat neater by using awhile
loop (something likewhile IFS=';' read -r username passwd full_name group second_group; do stuff; done < ./user_sheet.csv
)
– steeldriver
1 min ago
add a comment |
up vote
0
down vote
The final code is this for anyone that is curious:
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
psswd=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2)
full_name=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3)
group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4)
second_group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5)
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
if [ "$second_group" = LPGestionnaires ]
then
sudo usermod -a -G LPGestionnaires "$username"
fi
echo "$username:$psswd" | sudo chpasswd
((counter++))
done
echo Execution complete
New contributor
You're almost re-inventing thenewusers
command here - at the very least, your script could be made somewhat neater by using awhile
loop (something likewhile IFS=';' read -r username passwd full_name group second_group; do stuff; done < ./user_sheet.csv
)
– steeldriver
1 min ago
add a comment |
up vote
0
down vote
up vote
0
down vote
The final code is this for anyone that is curious:
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
psswd=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2)
full_name=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3)
group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4)
second_group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5)
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
if [ "$second_group" = LPGestionnaires ]
then
sudo usermod -a -G LPGestionnaires "$username"
fi
echo "$username:$psswd" | sudo chpasswd
((counter++))
done
echo Execution complete
New contributor
The final code is this for anyone that is curious:
#!/bin/bash
counter=2
while [ $counter -lt 19 ]
do
username=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f1)
psswd=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f2)
full_name=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f3)
group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f4)
second_group=$(head -n $counter ./user_sheet.csv | tail -n 1 | cut -d ';' -f5)
sudo useradd "$username" -m -g "$group" -s /bin/bash -c "$full_name"
if [ "$second_group" = LPGestionnaires ]
then
sudo usermod -a -G LPGestionnaires "$username"
fi
echo "$username:$psswd" | sudo chpasswd
((counter++))
done
echo Execution complete
New contributor
New contributor
answered 29 mins ago
moltenmath
83
83
New contributor
New contributor
You're almost re-inventing thenewusers
command here - at the very least, your script could be made somewhat neater by using awhile
loop (something likewhile IFS=';' read -r username passwd full_name group second_group; do stuff; done < ./user_sheet.csv
)
– steeldriver
1 min ago
add a comment |
You're almost re-inventing thenewusers
command here - at the very least, your script could be made somewhat neater by using awhile
loop (something likewhile IFS=';' read -r username passwd full_name group second_group; do stuff; done < ./user_sheet.csv
)
– steeldriver
1 min ago
You're almost re-inventing the
newusers
command here - at the very least, your script could be made somewhat neater by using a while
loop (something like while IFS=';' read -r username passwd full_name group second_group; do stuff; done < ./user_sheet.csv
)– steeldriver
1 min ago
You're almost re-inventing the
newusers
command here - at the very least, your script could be made somewhat neater by using a while
loop (something like while IFS=';' read -r username passwd full_name group second_group; do stuff; done < ./user_sheet.csv
)– steeldriver
1 min ago
add a comment |
moltenmath is a new contributor. Be nice, and check out our Code of Conduct.
moltenmath is a new contributor. Be nice, and check out our Code of Conduct.
moltenmath is a new contributor. Be nice, and check out our Code of Conduct.
moltenmath is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1102437%2fan-option-is-not-seeing-an-argument-that-is-a-variable-in-bash-please-help%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown