LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell Scripting - Need some help (https://www.linuxquestions.org/questions/programming-9/shell-scripting-need-some-help-17276/)

The Grepper 03-29-2002 09:53 AM

Shell Scripting - Need some help
 
HELP ${var%/*}
Hello

I have a list of a whole bunch of cpp files, and their directories
for ex.

C/program/test.cpp
C/program/test1.h
C/personal/math.h
C/personal/iterate.cpp

Now I would like to use ${var%/*} to remove the names of the files and the last /, but i dont know how. I need to do this, so I can use sort and uniq, which would result in

C/program/
C/personal/

as being the directories that contain cpp files

Thanks

I think I should use something like ${varname%/*}, but im not sure how to use it.

I read file names off the command line, using $1, $2, I have the path saved in a variable called x
x=$1
in my loop i use find, and it prints the first list of directories

THanks for the hlep
:confused:

crabboy 03-29-2002 04:10 PM

You can try to use dirname:
Code:

echo "/pub/program/file1.c" | xargs dirname

or

dirname "/pub/program/file1.c"



All times are GMT -5. The time now is 01:15 PM.