Reputation: 23
I wrote a simple test script having the below code
#!/bin/bash
CHM=test
NAME="user@test"
if ! grep -q test /etc/passwd
then
useradd -s /bin/bash -m -d /home/test -c "${CHM} : ${NAME}" test
fi
but I'm having problem with bash converting my " to ' example output
+ CHM=test
+ NAME=user@test
+ grep -q test /etc/passwd
+ useradd -s /bin/bash -m -d /home/test -c 'test : user@test' test
useradd: invalid comment 'test : user@test'
I can't figure how to fix this any input is welcome, try to search but does not yield any preferred result
OS: RHEL6 GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu Thanks
Upvotes: 1
Views: 942
Reputation: 72629
Bash doesn't convert any quotes, this is purely an output artifact of set -x
. As you can see, the ${VARIABLES}
have been expanded in the set -x
output. After that the quote type no longer matters and the bash maintainer chose to display all words containing blanks in single quotes to make the word boundaries clear.
The actual problem, as codegrep_admin correctly identified, is the impossibility to use a colon :
for any field in /etc/passwd
. E.g. you can't have a user named foo:bar
and you can't have a comment saying test:user@test
and you can't have a shell named ba:sh
.
Upvotes: 2
Reputation: 529
/etc/passwd
is delimited by :
character and hence useradd is rejecting the comment. Try removing :
in your comment.
Upvotes: 2