I have a script that is receiving the full path and filename as 1 parm. Example: dir1/dir2/test.txt.
I need to split the path and filename into 2 variables.
dir = dir1/dir2
file = test.txtEric

One way uses unix commands and one way uses bash/ksh pattern matching operators:
#!/bin/kshvar=dir1/dir2/test.txt
# use the unix basename command
file=$(basename $var)
echo $file# use the unix dirname command
dir=$(dirname $var)
echo $dir# use ksh/bash patterns
# Using ksh pattern-matching operators, this function
# replaces the unix basename command. If a 2nd argument
# exists, strip off the extension.
function my_basename {
typeset v xv=${1##*/}
x=${2#.} # get rid of the '.'
v=${v%.$x}
echo $v
}
# Using ksh pattern-matching operators, this function
# replaces the unix dirname command.
function my_dirname {
typeset v="$@"echo ${v%/*}
}
ffile=$(my_basename $var)
echo $ffile
ddir=$(my_dirname $var)
echo $ddir
Thanks Nails... I needed to parse the parm inorder to cd to the directory and then ftp the file.
That worked.
Eric
Eric
