southbeach
Programmer
I have this simple script
I need to extract the file name off a given directory tree or path. I am having hell of a hard time comparing two simple strings as attempted above.
I have tried various approaches using awk and other syntax as I've found online but nothing seems to work.
I have resolved to parse through the string from end of string back until I find the first "/" thus presumably having successfully extracted the file name into a string "$fname"
That being said, I am running into an "arithmetic syntax error" on line 10 that reads
Any assistance with this will be truly appreciated!
Thanks,
--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
Code:
#!/bin/ksh
MyString=/dir/dir/dir/34/54/39/98-1.pdf
x=${#MyString}
echo "x: ${x}"
y=1
#while (( y <= ${#MyString} ))
while (( x > 0 ))
do
xchar=$(expr substr "$MyString" $x 1)
if (( "${xchar}" == "/" ));
then
echo "fname set to: ${fname}"
exit
fi
fname="${xchar}${fname}"
let x=x-1
done
I have tried various approaches using awk and other syntax as I've found online but nothing seems to work.
I have resolved to parse through the string from end of string back until I find the first "/" thus presumably having successfully extracted the file name into a string "$fname"
That being said, I am running into an "arithmetic syntax error" on line 10 that reads
Code:
line 10: "f" == "/" : arithmetic syntax error
Any assistance with this will be truly appreciated!
Thanks,
--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.