How to change umask in shell scripting?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to change umask in shell scripting?
# 1  
Old 11-07-2012
Question How to change umask in shell scripting?

Hi,

I have manually changed umak value by umask 0033 , After that i would like to change umask value into 0022 through shell scripting..

But it is changing while running the script. Once come out from script, it has not changed ...

Ex:
Code:
>umask
0033
>./1.sh
0022
>umask
0033

plz Any suggestion ?

Last edited by Franklin52; 11-07-2012 at 06:54 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 11-07-2012
One of the things about inheriting settings is that you can't inherit from your children in order to apply the change to the current shell (rather than the shell spawned for the script to run in) you would have to invoke the commands in the script in the current shell using the dot "." operator eg.
Code:
~/$ . ~/.profile

# 3  
Old 11-07-2012
Hi Again,

This is a my code :
Code:
#!/bin/bash

umask
echo " Before profile execute"
. $HOME/.profile
echo " After profile execute"
umask

Note: umask 0022 value is present in . $HOME/.profile file.

Execution steps:
Code:
[scrbgcddkcph411:/opt/apps/gxadm]$ umask
0033
[scrbgcddkcph411:/opt/apps/gxadm]$ ./1.sh
0033
 Before profile execute
 After profile execute
0022
[scrbgcddkcph411:/opt/apps/gxadm]$ umask
0033

any advice , I would like to change umask value

Last edited by Franklin52; 11-07-2012 at 06:53 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 11-07-2012
I meant that you should execute the commands in the script in the current shell, like so:
Code:
user@busybox ~/$ umask
0022
user@busybox ~/$ cat test.sh
#!/bin/bash

umask 033
user@busybox ~/$ . test.sh
user@busybox ~/$ umask
0033

Calling the script spawns a new shell process which ceases to exist when the script exits. You need to execute the commands in the context of the current shell, hence the use of dot opperator ".".
# 5  
Old 11-08-2012
Ok. But before .profile execution. I need to perform one function. In this case, it is not working fine.
Any permanent solution for this.

Note: Some time, user can run script by ./script

Or Any other alternative way is appreciable.

( My requirement is that Already i am executing one script. which is cover all the our rquirement ( lot of function are included in that script).But newly we would like to change umask value through that script. We have tried 2 way
1) Already umask values is present in .profile file. so we tried to execute that file in that script by . <.profile>
2) Just we added umask 0022 value in top of the script .

Both are not working. we are not achieved goal.

Please advice or suggest on this

Thanks,
Mani
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Change umask for apache user

Hi, I need to change the umask for apache user so that the other group memebers have write access to the files. The apache user has no login shell running under centos 5.6. Currently apache user have 022 umask and i need to change to 002 so that other group memeber can have write access to that... (1 Reply)
Discussion started by: phanidhar6039
1 Replies

2. Shell Programming and Scripting

Need help to change XML values with shell scripting for Network Simulation

Hello, I don't have experience in this scripting and I need some help to read a value from an XML file and change it with a random number to use in simulator for different network scenarios. </Description><sim_comm_rounds>35</sim_comm_rounds><num_clusters>1</num_clusters><Clocking> I want to... (5 Replies)
Discussion started by: erhanasd
5 Replies

3. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

4. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

5. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

6. UNIX for Dummies Questions & Answers

How to change Case of a string(BASH Scripting)?

Is there any inbuilt functionality in Unix shell script so that i can able to convert lower case string input to an upper case? I dont want to use high level languages like java,python or perl for doing the job. (2 Replies)
Discussion started by: pinga123
2 Replies

7. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

8. Shell Programming and Scripting

Scripting change of text in another file

Hello, I am pretty new to UNIX/bash scripting, so this question may seem obvious. My experience is simply stringing commands together in a script, maybe doing some if/then testing and such, so I haven't gotten into anything too heavy... I have a shell script that I use as a template to create... (7 Replies)
Discussion started by: vwgtiturbo
7 Replies

9. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question