Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create maildirs with unix script, so question is how to create directory like in this example:

if i have only three arguments - mailserver ( and username (john) and time I don`t know how to make that "split part" for unix script, how to extract first three letters for username john look like example above. Thank you in advance!

share|improve this question

In bash you can use the ${} substring match to get a single letter from a string:

coredump@anita:~$ x="john"; echo ${x:0:1}
coredump@anita:~$ x="john"; echo ${x:1:1}
coredump@anita:~$ x="john"; echo ${x:2:1}

So in your script you can assign those letters to variables and use it on the mkdir commands to create your directory structure, something like this I suppose:


share|improve this answer
great! it works! – user77473 Apr 7 '11 at 12:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.