Sponsored Content
Top Forums Shell Programming and Scripting Getting pathname variables with ksh Post 83365 by BCarlson on Wednesday 14th of September 2005 09:21:32 AM
Old 09-14-2005
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.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

variables in ksh

I'm new to unix scripting. How would I go about pulling the first 3 characters from a variable in ksh and storing in another variable? Thanks. (9 Replies)
Discussion started by: steve6368
9 Replies

2. UNIX for Advanced & Expert Users

Ksh - Env. Variables ??

Hey all, I have been using Ksh and in that I am setting Environment variables. To set Env. Variables I have created my own file "BuildScript.sh" in which i have written : export CLASSPATH=/somedir/some other dir/file:. export PATH=/some dir/file:. But when i am calling this... (4 Replies)
Discussion started by: varungupta
4 Replies

3. Shell Programming and Scripting

subtracting variables in ksh

hi all, how do i subract variables in shell ?? am trying to space out the headers and the output generated by the shell so they all line up : currently the output is like this : servers : users server1 : 10 latestServer : 50 so i thought... (3 Replies)
Discussion started by: cesarNZ
3 Replies

4. Shell Programming and Scripting

How to preserve NL in Ksh variables?

I'm trying to set a variable to the output of a command. This is what the comand output to the display looks like: />hciconndump -v TOsiu Dump of connection(s): TOsiu ---------------------------------------------------------------------- Process: A60Tsiu Connection: TOsiu... (2 Replies)
Discussion started by: troym72
2 Replies

5. Shell Programming and Scripting

Combining two variables in ksh

I can't believe I can't figure this out... given this code: CARS_DATA_LIST=`cat /tmp/file1 | awk '{print $1}' ` FMSA_DATA_LIST=`cat /tmp/file2 | awk '{print $1}' ` The value of each of the above variables is: CARS = a b c d e f g FMSA = a b c q r s I want to declare a third... (8 Replies)
Discussion started by: Shoeless_Mike
8 Replies

6. Shell Programming and Scripting

ksh - for loop with variables

Hi, I 'm trying to send an e-mail for every different line in the .txt for i in {1..$variable} do sed -n "/$i$/p" text.txt done I have two problems about this. First one is that for loop doesn't work and the second one is that i cant get the output of sed (4 Replies)
Discussion started by: ozum
4 Replies

7. Shell Programming and Scripting

Help cannot concatenate Ksh variables ?

Cannot combine these two strings into one line, either as a 3rd variable or echo or printing ? Frustrating. for i in `cat /scripts/pathList.dat` do OldRepo= grep Oldhostname ${i}/.svn/entries | tail -1 NewRepo= grep Oldhostname ${i}/.svn/entries | tail -1 | sed '/Oldhostname/... (41 Replies)
Discussion started by: pcpinkerton
41 Replies

8. UNIX for Dummies Questions & Answers

Formating variables in KSH

Hi Friends , I want to know how to format the output for the following: i searched in the forum and couldnt get the exact requirement. Thanks in advance . (2 Replies)
Discussion started by: i150371485
2 Replies

9. Shell Programming and Scripting

ksh - keep argument variables after ssh

i have a script that should ssh to different host/server. See below: ./script.ksh var1 var2 var3 case $ser in ser1) depo='appr1' set -A aprrA aprrB ssh ser2 "/home/dir/script.ksh $1 $2 $3" ssh ser3 "/home/dir/script.ksh $1 $2 $3" ssh ser4... (4 Replies)
Discussion started by: erin00
4 Replies

10. Shell Programming and Scripting

awk - using variables in pattern which contain full pathname

Hello. I would like to make this bash command working. In the following code, the bash variable 'ZYPPER_LOCAL_REP' contain a full pathname like '/path/to/path/somewhere' The command list all available repositories, search for the string 'zipper_local' then on the same line search for... (4 Replies)
Discussion started by: jcdole
4 Replies
Path(3pm)						User Contributed Perl Documentation						 Path(3pm)

NAME
Env::Path - Advanced operations on path variables SYNOPSIS
use Env::Path; # basic usage my $manpath = Env::Path->MANPATH; $manpath->Append('/opt/samba/man'); for ($manpath->List) { print $_, " " }; # similar to above using the "implicit object" shorthand Env::Path->MANPATH; MANPATH->Append('/opt/samba/man'); for (MANPATH->List) { print $_, " " }; # one-shot use Env::Path->PATH->Append('/usr/sbin'); # change instances of /usr/local/bin to an architecture-specific dir Env::Path->PATH->Replace('/usr/local/bin', "/usr/local/$ENV{PLATFORM}/bin"); # more complex use (different names for same semantics) my $libpath; if ($^O =~ /aix/) { $libpath = Env::Path->LIBPATH; } else { $libpath = Env::Path->LD_LIBRARY_PATH; } $libpath->Assign(qw(/usr/lib /usr/openwin/lib)); $libpath->Prepend('/usr/ucblib') unless $libpath->Contains('/usr/ucblib'); $libpath->InsertAfter('/usr/ucblib', '/xx/yy/zz'); $libpath->Uniqify; $libpath->DeleteNonexistent; $libpath->Remove('/usr/local/lib'); print $libpath->Name, ":"; for ($libpath->List) { print " $_" }; print " "; # simplest usage: bless all existing EV's as Env::Path objects use Env::Path ':all'; my @cats = PATH->Whence('cat*'); print "@cats "; DESCRIPTION
Env::Path presents an object-oriented interface to path variables, defined as that subclass of environment variables which name an ordered list of filesystem elements separated by a platform-standard separator (typically ':' on UNIX and ';' on Windows). Of course, core Perl constructs such $ENV{PATH} .= ":/usr/local/bin"; will suffice for most uses. Env::Path is for the others; cases where you need to insert or remove interior path entries, strip redundancies, operate on a pathvar without having to know whether the current platform uses ":" or ";", operate on a pathvar which may have a different name on different platforms, etc. The OO interface is slightly unusual in that the environment variable is itself the object and the constructor is Env::Path->AUTOLOAD(); thus Env::Path->MANPATH; will bless $ENV{MANPATH} into its package while leaving it otherwise unmodified (with the exception of possible autovivification). Unlike most objects, this is a scalar and thus can have only one attribute; its value. In other words, Env::Path simply defines a set of methods a path variable may call on itself without changing the variable's value or other semantics. Also, while the object reference may be assigned and used in the normal style my $path = Env::Path->CLASSPATH; $path->Append('/opt/foo/classes.jar'); a shorthand is also available: Env::Path->CLASSPATH; CLASSPATH->Append('/opt/foo/classes.jar'); I.e. the name of the path variable may be used as a proxy for its object reference. This may be done at 'use' time too: use Env::Path qw(PATH CLASSPATH); # or qw(:all) to bless all EV's CLASSPATH->Append('/opt/foo/classes.jar'); The design is intended to make use of this module as lightweight as possible. Rather than creating a new object to manage an environment variable, the environment variable is provided a set of methods for self-modification but is otherwise left undisturbed and can be used in all normal ways. CLASS METHODS o <CONSTRUCTOR> The constructor may have any name; it's assumed to name a path variable as defined above. Returns the object reference. o PathSeparator Returns or sets the platform-specific path separator character, by default : on open platforms and ; on monopolistic ones. INSTANCE METHODS Unless otherwise indicated these methods return the object reference, allowing method calls to be strung together. All methods which take lists join them together using the value of "Env::Path->PathSeparator". o Name Returns the name of the pathvar. o Contains Returns true iff the specified entry is present in the pathvar. o Assign Takes a list and sets the pathvar to that value, separated by the current PathSeparator. o List Returns the current path in list format. o Prepend For each entry in the supplied list, removes it from the pathvar if present and prepends it, thus ensuring that it's present exactly once and at the front. o Append Analogous to Prepend. o InsertBefore Takes a <dirname> and a list, inserts the list just before the first instance of the <dirname>. If dirname is not found, works just like Prepend. As with Prepend, duplicates of the supplied entries are removed. o InsertAfter Analogous to InsertBefore o Remove Removes the specified entries from the path. o Replace Takes a /pattern/ and a list. Traverses the path and replaces all entries which match the pattern with the concatenated list entries. o ListNonexistent Returns a list of all entries which do not exist as filesystem entities. o DeleteNonexistent Removes from the path all entries which do not exist as filesystem entities. o Uniqify Removes redundant entries (the 2nd through nth instances of each entry). o Whence Takes a pattern and returns an ordered list of all filenames found along the path which match it and are executable. o Shell Returns a string suitable for passing to a shell which would set and export the pathvar to its current value within the shell context. NOTES
o No provision is made for path variables which are not also environment variables, a situation which is technically possible but quite rare. o Except where necessary no assumption is made that path entries should be directories, because pathvars like CLASSPATH may contain "virtual dirs" such as zip/jar files. For instance the DeleteNonexistent method does not remove entries which are files. In Perl terms the test applied is "-e", not "-d". o The shorthand notation for pathvar FOO is implemented by hacking @FOO::ISA, so there's a slight risk of namespace collision if your code also creates packages with all-upper-case names. No packages are created unless the shorthand notation is employed. o There's some cute code in the Env module by Gregor N. Purdy for splitting pathvars into arrays using ties. I'd love to be able to take advantage of that, and it pains me to do the same thing (and not as well) here rather than using Env. Unfortunately it's a newish feature (5.6.0? 5.005? 5.6.1?) in Env and I don't want Env::Path to be "tied" to the very latest Perls. WORKS ON
UNIX and Windows. AUTHOR
David Boyce <dsbperl AT boyski.com> COPYRIGHT
Copyright (c) 2000-2001 David Boyce. All rights reserved. This Perl program is free software; you may redistribute and/or modify it under the same terms as Perl itself. SEE ALSO
perl(1), perlobj(1), Env::Array(3) perl v5.10.1 2006-11-09 Path(3pm)
All times are GMT -4. The time now is 01:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy