Bad : modifier in $ (:).
Nowadays most of the people use bash as the default shell, even if there are some other options like ksh (or Korn Shell) and tcsh (the Tenex C Shell).
Bash is the default shell in almost all Linux distributions and it is quite popular but, if you are using some other Unix flavours (like BSD ones) you can find yourself using ksh (default shell in OpenBSD) or tcsh (one of the default shells in FreeBSD).
Today I found one of those ugly errors when doing some things with tcsh. The task was about to create a bunch of user accounts in a somehow automated way. As adduser in FreeBSD allows us to create users automatically, I just tried to do it in a foreach loop, which in tcsh was something like:
# foreach i ( usera userb userc userd ) foreach? echo "$i::1005::::$i SFTP account:/home/sftp/$i:/bin/tcsh:" | adduser -w random -f "-" foreach? end Bad : modifier in $ (:). #
I was executing that code directly in the shell (instead of writing a small script) and it should create the users ( usera userb userc userd ) with a random password associated with each one.
You probably noticed the error:
Bad : modifier in $ (:).
This happens because tcsh didn't handle the :$i thing properly. The correct way to do this in tcsh is:
echo $i"::1005::::"$i" SFTP account:/home/sftp/"$i":/bin/tcsh:" | adduser -w random -f "-"
Just leaving the $i variables outside of the "" strings.
Then it worked just fine:
# foreach i ( usera userb userc userd ) foreach? echo $i"::1005::::"$i" SFTP account:/home/sftp/"$i":/bin/tcsh:" | adduser -w random -f "-" foreach? end adduser: INFO: Successfully added (usera) to the user database. adduser: INFO: Password for (usera) is: XXXXXXXXXXX adduser: INFO: Successfully added (userb) to the user database. adduser: INFO: Password for (userb) is: XXXXXXXXXXX adduser: INFO: Successfully added (userc) to the user database. adduser: INFO: Password for (userc) is: XXXXXXXXXXX adduser: INFO: Successfully added (userd) to the user database. adduser: INFO: Password for (userd) is: XXXXXXXXXXX #
You can find similar errors like:
- Bad : modifier in $ ($).
- Bad : modifier in $ (/).
But the problem is probably the same as here, you are messing up with some variables in your shell code.