- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to make scripts executable automatically?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-01-2010 04:42 PM
тАО03-01-2010 04:42 PM
I want to make any scripts that I create executable by default, how can I achieve that?
By scripts I mean .sh, .bash & .pl.
Thanks,
Allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-01-2010 05:10 PM
тАО03-01-2010 05:10 PM
Solutiona) it should have a valid interpreter specified in the first line, e.g. "#!/bin/sh", "#!/usr/bin/perl" or whatever.
b) it should be placed in a directory that is listed in your PATH
(You can add the current directory "." to your path if you really want; but if you feel you must do it, please place it as the _last_ element in your PATH. Don't do it at all if you are root, or the next entry in some "Unix sysadmin horror stories" thread might be yours.)
c) it should have the execute permission bit set: chmod a+x
I guess your problem is most likely c).
Create a script, shell function or alias that will do two things:
1.) invoke your favorite editor to create/edit your script(s),
2.) after the editor process ends, runs chmod a+x on the same file.
Use this script to edit and create scripts instead of your regular editor command.
For a trivial example:
---begin script "/usr/local/bin/es"---
#!/bin/sh
${EDITOR:-vi} "$@"
chmod a+x "$@"
---end script---
es = Edit Script.
Set the environment variable EDITOR to your favorite editor. If the variable is not set, "vi" is used, as is the common convention in Unix systems.
Example:
es somescript.sh
If you use a "programmable" editor (like Emacs for example), it might even be possible to make the editor detect when you're writing a script and automatically set the execute permission on the script.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-01-2010 05:26 PM
тАО03-01-2010 05:26 PM
Re: How to make scripts executable automatically?
As I understand your question, you can't, not directly. The permissions (modes) of a file are set at the file's 'open()' by supplying an octal 'mode'. For files, this mode is generally, 0666 as set by the shell (and most programs). For directories, a mode of 0777 is used.
Thus, any file created by the shell is going to have derive its permissions from 0666 "and-ed" with the process's umask. Thus, even with a 'umask' of 000, your file will still not have execute permissions.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-01-2010 05:34 PM
тАО03-01-2010 05:34 PM
Re: How to make scripts executable automatically?
one small thing , can you explain "${EDITOR:-vi}" ?
Thanks,
Allan,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-01-2010 05:39 PM
тАО03-01-2010 05:39 PM
Re: How to make scripts executable automatically?
> one small thing , can you explain "${EDITOR:-vi}" ?
See your friendly manpages for 'sh-posix':
${parameter:-word}
If parameter is set and is nonnull, substitute its value; otherwise, substitute word.
Thus, set your EDITOR to 'vi' unless its already set to something else.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2010 12:51 AM
тАО03-02-2010 12:51 AM
Re: How to make scripts executable automatically?
Why would you want that? How would vi tell if it is a script?
You can always use chmod after you use vi. Or you can use:
:!chmod a+x %
after you write the file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-18-2010 04:48 AM
тАО05-18-2010 04:48 AM
Re: How to make scripts executable automatically?
There is a better way to do, what you are looking for, if you are using vi editor.
You can make use of 'autocmd' of vi.
Say, if you are going to create an expect script, with .exp extension, you need to follow the following steps.
1. Add a file say, ~/exp_header.txt
2. Add following lines in ~/exp_header.txt
:insert
#!/usr/bin/expect -f
[You can add additional header, e.g., Author, Date, Description etc. here]
3. Add following lines in your ~/.exrc file,
autocmd bufnewfile *.exp so ~/exp_header.txt
autocmd BufwritePost *.exp execute "!chmod +x " .expand("%")
So, whenever you are creating a new .exp file, vi will add "#!/usr/bin/expect -f" on the first line of the file. And when you are saving the file vi will change the file mode to executable.
Now you can use ./abc.exp
Thanks,
Pradosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2010 08:11 AM
тАО05-22-2010 08:11 AM
Re: How to make scripts executable automatically?
This is for vim, not vi.