Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Q] How to run "umask" in tcl?

598 views
Skip to first unread message

Cheng Qian

unread,
Jun 19, 1996, 3:00:00 AM6/19/96
to

[Question]
I need to change umask in Tcl program, I have tried "exec", the following
results shows it doesn't work. Please help me solve this problem.

Thanks.

% umask
invalid command name "umask"
% exec umask
couldn't execute "umask": No such file or directory


--
--Cheng Qian---------------------------------
- LSI Logic Corporation -
- Email: qi...@lsil.com -
- Phone: (408)433-7034 -
---------------------------------------------

Michael Schumacher

unread,
Jun 19, 1996, 3:00:00 AM6/19/96
to

Cheng Qian <qi...@lsil.com> wrote:
: [Question]

: I need to change umask in Tcl program, I have tried "exec", the following
: results shows it doesn't work. Please help me solve this problem.

: Thanks.

: % umask
: invalid command name "umask"
: % exec umask
: couldn't execute "umask": No such file or directory

"umask" is a shell (e.g. /bin/sh) builtin, so it can't be exec'd. You might
want to try TclX, which offers this command.


mike

Hume Smith

unread,
Jun 20, 1996, 3:00:00 AM6/20/96
to

In article <4qbsb4$c...@apollo.isisnet.com>, hcls...@isisnet.com says...

>I know of no standard tcl support for changing umask.

PS: all i can suggest is to use the permissions argument of open.


Hume Smith

unread,
Jun 20, 1996, 3:00:00 AM6/20/96
to

In article <4q7jfd$9...@lsi.lsil.com>, qi...@lsil.com says...

>I need to change umask in Tcl program, I have tried "exec", the following
>results shows it doesn't work. Please help me solve this problem.

>% umask


>invalid command name "umask"
>% exec umask
>couldn't execute "umask": No such file or directory

it doesn't work for exactly the same reasons that "exec setenv" and "exec cd"
don't work. there is no such executable, because the schmenge involved is
a per-process schmenge that cannot be altered by a child process.

Ray Calande

unread,
Jun 24, 1996, 3:00:00 AM6/24/96
to

Cheng Qian wrote:
> I need to change umask in Tcl program, I have tried "exec", the following
> results shows it doesn't work. Please help me solve this problem.
> % umask
> invalid command name "umask"
> % exec umask
> couldn't execute "umask": No such file or directory

1. Create a file "cmd.sh" with the word "umask" in it.

2. In your tcl script: exec cmd.sh

3. Open a pipe to read the results. See Welch book page 104 for example.

BTW I have found that any command or process that is arkward in tcl
directly can be done externally in a Bourne shell, Awk or Perl script.
The return is easily piped back into your tcl process.
--
# Raymond P. Calande work (408) 756-9517
# Avionics Systems Engineering 81-60
# Lockheed Martin Missiles & Space
# Sunnyvale, CA 94089

Paul Alexander

unread,
Jun 25, 1996, 3:00:00 AM6/25/96
to

>Cheng Qian wrote:
>> I need to change umask in Tcl program, I have tried "exec", the following
>> results shows it doesn't work. Please help me solve this problem.
>> % umask
>> invalid command name "umask"
>> % exec umask
>> couldn't execute "umask": No such file or directory

Most likely the path you have set when running the tcl script does not
include the location of umask (its possible you normally use a shell built-in
version). Therefore locate where umask is on your system either:

which umask

or if that says it is a shell builtin, try man umask. I'd guess looking
in /use/bin as a first place. Having found where umask is then use the full path
in your script, e.g.

exec /usr/bin/umask


Paul Alexander
Mullard Radio Astronomy Observatory,
Department of Physics, Cavendish Laboratory,
University of Cambridge, Cambridge, UK.

FAX: 44 1223 354 599
Tel: 44 1223 337 308

Roger Books

unread,
Jun 25, 1996, 3:00:00 AM6/25/96
to

Hume Smith (hcls...@isisnet.com) wrote:
> In article <4qbsb4$c...@apollo.isisnet.com>, hcls...@isisnet.com says...

> >I know of no standard tcl support for changing umask.

> PS: all i can suggest is to use the permissions argument of open.

This is probably in a FAQ somewhere, but can someone explain to me
why:

If I do:

open test.file w 0700
exit

ls -l test.file

I get -rwx------

but if I do

open test.file w 0770

I get -rwxr-x---

and 0777

gives me -rwxr-xr-x

I guess the question is why can't I give group or world write permission?
It looks like someone is trying to protect me from myself, which is of
course rather Mac-VMS-like, but not something I particularly want to see.

Roger
(If you stop me from shooting myself in the foot you make my life miserable
when I need to do something close to shooting myself in the foot.)

John Haxby

unread,
Jun 27, 1996, 3:00:00 AM6/27/96
to
Mark Diekhans wrote:
>
> This happens because the Unix open system call or mode with the
> inverse of the umask. You can either:
>
> o Get TclX so you have a umask built-in.
> o exec chmod after creating the file.
>
> Its one of the thinks I never like in the Unix API.

The umask(2) system call was introduced in Edition 7, if memory serves
me aright. So it must be perfect :-) No, seriously, umask is there for
a very good reason. Suppose, for example, that in an editor you want to
create a new file with the user's preferred accessibility. Typically,
this preference will be to disallow writing by others and/or the group.
You can do this for that specific editor quite easily by adding an
option to an option file. However, "ed" doesn't (or didn't) have an
option file... There are also many other programs that create files,
for example, "ld" (which creates executables) and the shell (with ">").

So, to catch the most common cases, a umask system call was added. This
is a mask of the permission bits that you want cleared when a file with
general permissions is created. Read that again, note especially the
word "cleared" -- this is what give people the most trouble.

Typically, the umask is 002 or 022. Bear in mind that these numbers are
in octal. If you use chmod to set a file to mode 002, you'll see it has
write permission for others and no one else -- this is probably not very
useful and exactly the opposite of what you want.

Now, given the umask, programs don't have to second guess what access
the user wants to grant to files when they are created and you don't
need an options file for everything under the sun. Editors, the shell
and so on, create files mode 0666 knowing that the permission bits the
user doesn't want will be cleared leaving an actual mode of (usually)
0664 or 0644. Similarly, ld, when writing executables, creates them
mode 0777 so that, usually, they wind up mode 0775 or 0755.

The umask is almost always used to toggle default group access (that is,
it's usually 002 to allow it or 022 to prevent it). Some people,
however, are extra paranoid and have a umask of 027 which prevents group
write and all access by others. The worst I ever saw was 047 which only
allowed group execute access. This has interesting consequences for
directories.

I trust that makes things slightly clearer. Tcl really ought to have
access to the umask system call and either emulate it or ignore it on
non-UNIX platforms.

One final plea: when you create a file, don't make it executable
*unless* you intend the file to be executed -- create files mode 0666
and you won't go far wrong.

--
John Haxby
These are my opinions, not my employer's.

Flemming Madsen

unread,
Jun 27, 1996, 3:00:00 AM6/27/96
to
In article <4qma1d$d...@butch.lmsc.lockheed.com>, Ray Calande <"raycalande@eagle"@lmsc.lockheed.com> writes:
>Cheng Qian wrote:
>> I need to change umask in Tcl program, I have tried "exec", the following
>> results shows it doesn't work. Please help me solve this problem.
>> % umask
>> invalid command name "umask"
>> % exec umask
>> couldn't execute "umask": No such file or directory
>

Load extended tcl (TclX) and utilize 'umask'

Have a nice day

/Flemming


Donal K. Fellows

unread,
Jun 28, 1996, 3:00:00 AM6/28/96
to
In article <4qs86i$k...@butch.lmsc.lockheed.com>,
Ray Calande <"raycalande@eagle"@lmsc.lockheed.com> wrote:
> I would also like to know why we are getting these results.
> My results are:
>
> w 0700 > -rwx------
> w 0770 > -rwxr-x---
> w 0777 > -rwxr-x---

Your umask is 0027 (turning off the write bit for groups and all
access for others). Either:
a) Do a umask in the shell you're calling tcl from (the default is
inherited from the tcl process' parent) You could even extend
your startup hack to include this

#!/bin/sh
# Set our umask to something sensible... \
umask 0022
# Now we exec tclsh and get on with it... \
exec tclsh7.5 $0 "$@"

b) Link with (or dynamically load) tclX which has umask built in

c) Write your own in C (not hard at all)

Donal.
--
Donal K. Fellows, (at work) | Donal K. Fellows, (at home)
Dept. of Computer Science, | 6, Randall Place, Heaton,
University of Manchester | Bradford, BD9 4AE
U.K. Tel: ++44-161-275-6137 | U.K. Tel: ++44-1274-401017
fell...@cs.man.ac.uk (preferred) | do...@ugglan.demon.co.uk (if you must)
--------------------------------------------------------------------------
<http://r8h.cs.man.ac.uk:8000/> for my home page

Roger Books

unread,
Jun 28, 1996, 3:00:00 AM6/28/96
to
Ray Calande ("raycalande@eagle"@lmsc.lockheed.com) wrote:
> Roger Books wrote:
> > open test.file w 0700

> > ls -l test.file
> > I get -rwx------
> >
> > open test.file w 0770
> > I get -rwxr-x---
> >
> > and 0777
> > gives me -rwxr-xr-x

> I would also like to know why we are getting these results.
> My results are:

> w 0700 > -rwx------
> w 0770 > -rwxr-x---
> w 0777 > -rwxr-x---

It was pointed out to me in email. The open permissions are the
and of what you ask for and the inverse of the umask, so for example,
if your umask is: 022, the octal inverse would be 755, that
anded with my desired perms of 777 give 755.

Roger

(Don't blame tcl, this comes from the C open command)

0 new messages