- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script to edit a file using 'vi'
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
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
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
тАО10-13-2002 08:36 PM
тАО10-13-2002 08:36 PM
Let's say the script is called viScript. The usage should be viScript [filename].
Before using vi to edit the file, it creates a backup copy first.
The script must accept one or no parameter from the command line. If no parameter is entered, then prompt the user to enter one. If none is entered then exit. If more than one is entered then display a usage message and exit.
When a filename is entered, it must check whether the file exists and has either read-only or read/write permission for the file. An error message appears if the file does not exist or if the user does not have read-only or read/write permission.
If the user has read-only access to the file, a message is displayed to that effect and along with the file contents. This means that the user can display the file only but not edit it.
If the user has read/write access, a copy of the file is made as filename.bak and then call vi to edit the file.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2002 09:19 PM
тАО10-13-2002 09:19 PM
SolutionAlternatively have a look at the HP Porting Centre. There are a number of editing tools, 'EMACS' could be one that your after.
Go to this link and use 'editor' without the quotes in the search.
http://hpux.connect.org.uk/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2002 09:42 PM
тАО10-13-2002 09:42 PM
Re: Shell script to edit a file using 'vi'
---
if [ $# -eq 0 ]; then
echo "Please insert filename \c"
read infile
else
infile=$1
fi
---
Before using vi to edit the file, it creates a backup copy first.
---
cp $infile $infile.$USER,`date`
---
When a filename is entered, it must check whether the file exists and has either read-only or read/write permission for the file. An error message appears if the file does not exist or if the user does not have read-only or read/write permission.
---
vi
---
If the user has read-only access to the file, a message is displayed to that effect and along with the file contents. This means that the user can display the file only but not edit it.
---
vi
---
If the user has read/write access, a copy of the file is made as filename.bak and then call vi to edit the file.
---
see above
---
vi does the most things you want to do
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-13-2002 10:42 PM
тАО10-13-2002 10:42 PM
Re: Shell script to edit a file using 'vi'
if what you need this script is just for taking backups before editing this file, try using emacs.
Other wise, a script could be like this.
[test conditions]
[backup file]
vi $filename
and when the user types :q in vi, the script terminates automatically.
hth
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2002 06:28 AM
тАО10-15-2002 06:28 AM
Re: Shell script to edit a file using 'vi'
Just my 2 cents worth...
Mark