![]() |
| ||
| Script to Change file permissions Hi I am new to unix and want to learn shell scripting. Right now I am use cygwin for windows but sooner I will switch to ubantu. So when I wrote my first script (just copied from the book I was reading), I came to know I have to give execute permission to the script file. So now I want to create a script which will take the file as input and will just change the permissions such that It wont effect read/write permission but only grant the execute permissions. So I tried to write something like this (code mixed with psuedocode is written below) #GrantExPer Please guide me for: 1. How to make a right command. I tried it by concatenate 2 strings. (line 4-7) 2. Then how to execute it. (line 8) 3. Is there any command which shows me file permissions in a number format like 644 rather than -rw-r--r--. To me number format seems easier to manipulate. Thanks |
| ||
| Re: Script to Change file permissions 1. #!/bin/bash 2. Put the above code in grant.sh, chmod a+x grant.sh, ./grant.sh 3. You can use 'stat' to get octal permissions. There are a number of approaches outlined at http://www.lockergnome.com/linux/200...c-permissions/ on getting octal perms. |
| ||
| Re: Script to Change file permissions thanks... other than error handling there is only one line... chmod u+x $1 and that's how we learn... I spent more than 1 hour on this.... Thank you very much... but i still want to know: how to concatenate two strings to make a command and then how to execute that command. Or do we need to always find a workaround. |
| ||
| Re: Script to Change file permissions sk@sk:~$ STR1='i' You can also use `` ticks to execute commands from output: sk@sk:~$ CURDIR=`pwd` |
| ||
| Re: Script to Change file permissions This is a better illustration of using ticks. It evaluates the command instead of taking the literal value: sk@sk:/tmp$ CURDIR=pwd |
| ||
| Re: Script to Change file permissions thanks... Now I understand how it works on shell prompt. I will try to find out if this works when written in a script. edit: it works in scripts also... thanks again. |
| ||
| Re: Script to Change file permissions The prompt and script are basically identical. If it works on the prompt it works in a script :) There may be a few minor differences but I can't think if any. Here is an example: sk@sk:/tmp$ if test -f /etc/passwd |
| ||
| Re: Script to Change file permissions ok.... that helps.. thanks again. |
| All times are GMT -4. The time now is 2:54 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC