![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to find out pathname from inode number | axes | UNIX for Advanced & Expert Users | 3 | 09-26-2008 06:44 AM |
| display pathname of the login shell | nadman123 | Shell Programming and Scripting | 1 | 04-14-2008 04:15 PM |
| how to get the last dir from a pathname using IFS | sam2004 | UNIX for Dummies Questions & Answers | 2 | 03-30-2005 07:34 PM |
| cpio restore - relative pathname | sureshy | UNIX for Dummies Questions & Answers | 4 | 08-27-2002 06:28 AM |
| find without pathname | MBGPS | UNIX for Dummies Questions & Answers | 3 | 06-27-2002 10:03 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Getting pathname variables with ksh
With C Shell you can get the root, head, tail and extension of a pathname by using pathname variable modifiers.
Example Script: #! /bin/csh set pathvar=/home/WSJ091305.txt echo $pathvar:r echo $pathvar:h echo $pathvar:t echo $pathvar:e The result of executing this script is: /home/WSJ091305 /home WSJ091305.txt txt My question is: How can this be done using ksh (I specifically need to get the extension)? Thanks in advance for the help. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Quote:
Code:
#!/bin/ksh
pathvar='/home/WSJ091305.txt'
echo "r->[${pathvar%%.*}]"
echo "h->[${pathvar%/*}]"
echo "t->[${pathvar##*/}]"
echo "e->[${pathvar#*.}]"
|
|
#3
|
|||
|
|||
|
Quote:
r->[/home/WSJ091305] h->[/home] t->[WSJ091305.txt] e->[txt] Is there a way to only get the results as with the csh? |
|
#4
|
||||
|
||||
|
well.... it's for you to see HOW it can be used.
|
|
#5
|
|||
|
|||
|
Will do.
Quote:
|
|
#6
|
|||
|
|||
|
I was able to get what I needed. Could you point me to some documentation that explains the commands you used to get this? Specifically, what all the characters do? I'm unfamiliar with them. Thanks so much for your help.
|
|
#7
|
||||
|
||||
|
Read the manuals.
In man ksh under the section Parameters In man sh under the section Parameter Expansion |
||||
| Google The UNIX and Linux Forums |