nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell Script To Add Execute permission to the file for the user

This is a discussion on Shell Script To Add Execute permission to the file for the user within the Shell scripting forums, part of the Development/Scripting category; hello... i have one question can you help me...??? please.. Write a script (Named execadd.sh) that will take a single ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2009, 11:15 PM
Junior Member
User
 
Join Date: Mar 2009
OS: Debian
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
midomax is on a distinguished road
Smile Shell Script To Add Execute permission to the file for the user

hello...
i have one question can you help me...???
please..
Write a script (Named execadd.sh) that will take a single filename as an argument and adds execute permission to the file for the user, but only if the file is a regular file.
Your script must check to see that there is exactly one argument. If there are no arguments or more than one arguments, your script must produce a "usage" message that tells how to use the script. You write it this way:
echo "Usage: $0 filename"
You must check to see if the file exists; if it doesn't, give an error message. You must check to see if the file is a regular file; if not, give an appropriate message

Reply With Quote
  #2 (permalink)  
Old 11-03-2009, 01:13 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try
Code:
#!/bin/bash
FILE=$1

usage(){
    echo "Usage: $0 filename"
    exit 1
}

[ $# -ne 1 ] && usage

if [ -f $FILE ]
then
    chmod +x $FILE
else
    echo "Error: $FILE not a regular file."
fi
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 11-03-2009, 06:06 AM
Junior Member
User
 
Join Date: Mar 2009
OS: Debian
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
midomax is on a distinguished road
Smile thanx

really thank you...only this solved....???i don,t understand any thing in linux....!!keep help me always please.beacause myspeciality in the netowrk .
Reply With Quote
  #4 (permalink)  
Old 11-03-2009, 06:32 AM
Junior Member
User
 
Join Date: Mar 2009
OS: Debian
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
midomax is on a distinguished road
Thumbs up ok

Dear nixcraft


i wish to Continuo the solved would you mind...due to i need it at nearest time ...
please ..
i'm waitting your response....

best regards
bye
Reply With Quote
  #5 (permalink)  
Old 11-03-2009, 10:49 PM
Junior Member
User
 
Join Date: Mar 2009
OS: Debian
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
midomax is on a distinguished road
Question plz guys i want more comprehensive answer

(write this script ) ???

Write a script (Named execadd.sh) that will take a single filename as an argument and adds execute permission to the file for the user, but only if the file is a regular file.
Your script must check to see that there is exactly one argument. If there are no arguments or more than one arguments, your script must produce a "usage" message that tells how to use the script. You write it this way:
echo "Usage: $0 filename"
You must check to see if the file exists; if it doesn't, give an error message. You must check to see if the file is a regular file; if not, give an appropriate message

What is The rest of this solution ...


#!/bin/bash
FILE=$1

usage(){
echo "Usage: $0 filename"
exit 1
}

[ $# -ne 1 ] && usage

if [ -f $FILE ]
then
chmod +x $FILE
else
echo "Error: $FILE not a regular file."
fi

.
.
.



Reply With Quote
  #6 (permalink)  
Old 12-03-2009, 12:35 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

This script is the solution. Feel free to modify it as per your requirements.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Linux Add User Shell Script abovenewbi Shell scripting 13 06-03-2009 02:57 AM
Execute UNIX Command / Shell Script Once In The Future permalac Shell scripting 2 27-08-2008 08:13 PM
Shell Script To Outputs File Permissions of Most Recently Modified File glen_4455 Shell scripting 1 25-08-2008 02:39 PM
shell script to search specific file from txt file inside zip file and extract it aasif.shaikh Shell scripting 2 31-05-2008 06:44 PM
If file modified execute a script karabaja Shell scripting 3 23-11-2006 02:39 AM


All times are GMT +5.5. The time now is 02:58 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38