In your example, your confusing shell scripting commands. You have to pay special attention to which scripting language you're using and then adhere to its commands' syntax. In your example you're using turbo C shell (tcsh) however you're then mixing in Bash/Bourne shell commands and syntaxes.
You can use the following approach if you truly want tcsh
. Say I had this sample file:
$ cat afile
1
2
3
4
5
And this script:
$ cat cmd.csh
#!/bin/tcsh
foreach i (`cat afile`)
echo "$i"
end
Running it will produce this output:
$ ./cmd.csh
1
2
3
4
5
So to complete the task, we can add in the mkdir
command after the echo
:
$ cat cmd1.csh
#!/bin/tcsh
foreach i (`cat afile`)
echo "making directory: $i"
mkdir "$i"
end
Now when we run it:
$ ./cmd1.csh
making directory: 1
making directory: 2
making directory: 3
making directory: 4
making directory: 5
Resulting in the directories getting created:
$ ls -l
total 32
drwxrwxr-x. 2 saml saml 4096 Oct 16 18:58 1
drwxrwxr-x. 2 saml saml 4096 Oct 16 18:58 2
drwxrwxr-x. 2 saml saml 4096 Oct 16 18:58 3
drwxrwxr-x. 2 saml saml 4096 Oct 16 18:58 4
drwxrwxr-x. 2 saml saml 4096 Oct 16 18:58 5
-rw-rw-r--. 1 saml saml 11 Oct 16 18:47 afile
-rwxrwxr-x. 1 saml saml 86 Oct 16 18:56 cmd1.csh
-rwxrwxr-x. 1 saml saml 55 Oct 16 18:51 cmd.csh
do
block withdone
? Also, you usename_id
to start, then refer tosubj_id
.for
isbash
, nottcsh
.tcsh
isforeach
, but it doesn't have ado
clause. Also, you misspelledtcsh
.tcsh
for scripting, use a POSIX-style shell. See faqs.org/faqs/unix-faq/shell/csh-whynot