- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script commands
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
Forums
Discussions
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
10-19-2000 09:22 AM
10-19-2000 09:22 AM
input when executing a script.
Suppose the users input two following files:
/path1/path2/path3/file1 and
/path1/path2/file2
Now, what command can I use to retrieve just
the file name and the pathname itself?
/path1/path2/path3 and file1
/path1/path2 and file2
TIA.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2000 09:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2000 09:32 AM
10-19-2000 09:32 AM
Re: Script commands
Use 'basename' to get the filename. Use 'dirname' to get the directory name. See man pages for 'basename'.
For example:
dirname /usr/src/cmd/cat.c
returns: /usr/src/cmd
basename /usr/src/cmd/cat.c
returns: cat.c
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2000 09:33 AM
10-19-2000 09:33 AM
Re: Script commands
basename $0
dirname $0
refer to man page of basename command for additional information
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2000 09:33 AM
10-19-2000 09:33 AM
Re: Script commands
Are you trying to split a filename into the directory part and the file part?
If so then you can do it as follows:-
#/usr/bin/sh
FN=/path1/path2/path3/file
FILE=${FN##*/}
DIR=${FN%/*}
The FILE= construct removes all characters up to the final / leaving 'file'
The DIR= construct removes the final / and everything after it, leaving '/path1/path2/path3'
Hope this helps,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2000 09:53 AM
10-19-2000 09:53 AM
Re: Script commands
You can try:
FULL_PATH=/path1/path2/file
echo $FULL_PATH | awk -F/ '{ printf "filename is" $(NF) "nPath is: " } { for (i = 2 ; i < NF; i++) printf $(i) }'
make changes as required