Bad : modifier in $ (:).
August 2019
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
About
This site is an effort to share some of the base knowledge I have gathered through all this years working with Linux, FreeBSD, OpenBSD, Python or Zope, among others. So, take a look around and I hope you will find the contents useful.
Recent Entries
Recent Comments
Recent Trackbacks
Categories
OpenBSD (9 items)
BSD (0 items)
FreeBSD (19 items)
Linux (3 items)
Security (3 items)
Python (22 items)
Zope (13 items)
Daily (144 items)
e-shell (9 items)
Hacks (14 items)
PostgreSQL (3 items)
OSX (8 items)
Nintendo DS (0 items)
enlightenment (0 items)
Apache (3 items)
Nintendo Wii (1 items)
Django (24 items)
Music (12 items)
Plone (7 items)
Varnish (0 items)
Lugo (2 items)
Sendmail (0 items)
europython (7 items)
Cherokee (1 items)
self (1 items)
Nature (1 items)
Hiking (0 items)
uwsgi (0 items)
nginx (0 items)
cycling (10 items)
Networking (1 items)
DNS (0 items)
Archives

Syndicate this site (XML)

RSS/RDF 0.91

27 septiembre
2010

Bad : modifier in $ (:).

tcsh proper variable handling in a "echo" call

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.

Posted by wu at 12:05 | Comments (0) | Trackbacks (0)
<< sshd: Corrupted MAC on input. | Main | Repair a GEOM mirror using a rescue-live system >>
Comments
There are no comments.
Trackbacks
Please send trackback to:http://blog.e-shell.org/271/tbping
There are no trackbacks.
Post a comment