OCC: Using FIRSTNAME *SPACE* LASTNAME as display name causes errors

Here it fails, because i use “123 123”. There is a space in the display name. (Yes in my script ive tried putting them in quotation marks.

Display Name: 123 123
Email-address: 123
Choose a group:
[1] group1
[2] group2
[3] group3

    Option: 1

SamAccountName: 1234

Not enough arguments (missing: “uid”).

user:add [–password-from-env] [–display-name [DISPLAY-NAME]] [-g|–group [GROUP]] [–]

Here it works. I use 123 as display name with no space in it.

Display Name: 123
Email-address: 123
Choose a group:
[1] group1
[2] group2
[3] group3

    Option: 1

SamAccountName: 123
The user “123” was created successfully
Display name set to “123”
User “123” added to group “group1”

ive tried to turn and twist this around as best I can but it seems the trouble appears when I use a space in the display name, to separate given name from surname. It seems to be impossible to set a display name on an existing account afterwards. I’ve tried this for a few hours but whatever changes you make in OCC doesnt apply to the account at all. (There is no previously configured value for display-name, even though the user account has a display-name on the website. )

Any help would be appreciated. :slight_smile: Sorry if there is any information lacking, I’ve tried to troubleshoot it myself and in order to find that is directly causing the issue.

Did you try this :
sudo -u www-data php occ user:add “John Doe”
Good Luck


Yes and this works. The only problem is that I can not import a password from environment this way. As it is, I use openssl to generate a password for me so that I won’t have to type it in myself . (To make the process more automatic)

Here is the relevant part of the script.

password=$(openssl rand -base64 14)

export OC_PASS=$password
su -s /bin/sh apache -c “php /var/www/html/nextcloud/occ user:add --password-from-env --display-name=”$name" --group="$group" $uid "

Have you tried “escaping” the space out with a backslash in your script?

Usually in command line arguments on *nix systems, you’d escape the space out in titles and path names with a backslash. So if you had a directory with a space (for example, “my files”), you’d change into it with:
cd ./my\ files/

If there’s a file name with a space (for example “pass words.txt”), you’d view it with:
less pass\ words.txt

I’d give that a try.

Sorry, I’m afraid you have lost me.

Where should I be “escaping” the space in my script? I’m a bit confused how I should go about doing that since the entire name is put into one string. ( $name )

True, sorry, I wasn’t thinking. I had it in my head you could rewrite part of the script to try a different method, but I don’t know how you’d use a backslash.

Taking a second look at your script, you use double quotes around the entire php section, but also double quotes within the section around variable names. Could that be part of the issue?

I mean, it looks like the php section excludes everything after:

Maybe try a mix of double and single quotes? (e.g. " " around the whole php section and ’ ’ around variables?) Do the $name and $group variables even need quotes around them?

I may be misunderstanding what your script is doing, but what about trying either:

su -s /bin/sh apache -c "php /var/www/html/nextcloud/occ user:add --password-from-env --display-name='$name' --group='$group' $uid"


su -s /bin/sh apache -c "php /var/www/html/nextcloud/occ user:add --password-from-env --display-name=$name --group=$group $uid"