basename not working why?
In C-shell :
when typing.. foreach f ( ' ../trip/*.jpg' ) foreach? set name = ' basename $f .jpg ' foreach? echo $name foreach? end result is : basename $f .jpg why id he basename not working and is there a way through it? |
Hi varunimast
there is an important difference in C-shells between double (") and single (') quotes. Within single quotes there is no variable replacement. Just try to replace your line Quote:
Quote:
Thomas |
Thanks for replying thomas.
But now its giving the result as : basename ls a.jpg b.jpg .jpg what must be done now? |
You need command substitution: use backticks `
Code:
foreach? set name = `basename $f .jpg` |
now the result is :
basename: extra operand `.jpg' Actually , what I have found is that "basename" command is not working properly, as when I applied it in another directory, it is not removing the directory path name. Again.. what must be done? |
Quote:
In alternative you can try sed, e.g. Code:
foreach? set name = `echo "$f" | sed 's/.*\///'` |
thank you colucix.
I have found the answer as suggested by you, by using the " backticks " not only in the set command but also in the foreach command. Now its working. Thanks again :) |
Great! I didn't notice that. Actually you should not use quotes at all in the foreach statement. This is a working version for me:
Code:
foreach f ( ../trip/*.jpg ) |
All times are GMT -5. The time now is 03:29 AM. |