Sorry
I have used basename foo2 and it returns foo2
I did not see the NF on the end - now I get 6 (yes 6!) returned to this script
dir=/home/foo1/foo2
splitit=`echo $dir | awk -F '/' '{print $NF}'`
echo $splitit
when i use the script below blank is returned
dir=/home/foo1/foo2
splitit=`echo $dir | awk -F '/' '{print $1}'`
echo $splitit
desired output is foo2.
last folder name is only known when the script is run (its run from another script)
Hm...... I don't see where '6' would be returned...
a 'blank' is what I would expect.
you're outputting '$1' - FIRST field. You have an ABSOLUTE path with the LEADING '/'.
What would be the FIRST field in a string '/a/b/c/d'?
It would be the string BEFORE the FIRST fieldSeparator. What is it in this case? It's the 'blank' character.
field1 -> 'blank'
field2 -> a
field3 -> b
field4 -> c
field5 -> d
yes my print field separator number was wrong thanks for explaining it well
I will now put the values in an array, get size of array and from last array value get name of last directory.
I think this is an over complicated way.
when I manned basename it seemed that you must give filename - this is unknown in my script
why? what is an array and why do you need a 'size of it'?
awk's 'NF' will give you the 'Number of Fields' [NF] of the crrect record already.
Using my previously posted solution using '$NF' should give you the value of the LAST field.
why are you saying that?
'basename' can take any PATH - be it path to a file OR a path to a directory.