bash script - read command


I wrote the following bash script which works fine as root:

echo -n "Which user do you want to assess (i.e. user196)? ";
read name1;
ls -l | grep $name1 | gawk ‘{ sum += $5 } END { print (sum/(1024*1024)),“MB” }’

Execution as follow:

eaghp7:/pascal/users/cfd/fred/test # source
Which user do you want to assess (i.e. user196)? user196
0.000159264 MB
eaghp7:/pascal/users/cfd/fred/test #

So far so good.
Now when executed as a user (user196) the following error message appears:

eaghp7 262% ls
total 5
drwxr-xr-x 2 user196 rdduk 80 2009-08-11 15:16 .
drwxr-xr-x 21 user196 rdduk 528 2009-08-11 13:24 …
-rwxrwxrwx 1 user196 rdduk 167 2009-08-11 15:16
eaghp7 263% source
Which user do you want to assess (i.e. user196)? read: Command not found.
name1: Undefined variable.
eaghp7 264%

The aim is to have the script executed by end users (no root password). How can I make it work for them please?

Any help is appreciated.



Are you using csh as your terminal shell by any chance?

When you do a source, the first line #!/bin/bash does nothing. The contents of the file are executed by the current shell as if you had typed them in. And read is not a built-in command known to csh. To make sure the commands in the script are executed by /bin/bash as you intended, you should execute the script, not source it.

chmod 755

It works fine if it’s made executable and use


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel
up 6 days 18:09, 2 users, load average: 0.09, 0.09, 0.18
GPU GeForce 8600 GTS Silent - Driver Version: 190.18

Thanks very much it works.