LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-31-2002, 02:02 PM   #1
The Grepper
LQ Newbie
 
Registered: Mar 2002
Posts: 9

Rep: Reputation: 0
${varname%/*}


Hello

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

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

Now I want to use ${varname%/*} to remove the names of the files and the last /, but i dont know how to use it. What should I put in carname?

x=$1
while [ "$2" ]
do
find $x -name "*.$2"
shift
done

the results should be like this
C/program/
C/personal/

as being the directories that contain cpp files

Thanks



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
 
Old 03-31-2002, 05:20 PM   #2
zmedico
Member
 
Registered: Feb 2002
Location: Mission Viejo, California, USA
Distribution: Gentoo
Posts: 707

Rep: Reputation: 30
Two programs that may be of use are "basename" and "cut" . See their "man pages" for details. Example:

man basename

Bash also has some string processing abilities built in. Here is the Advanced Bash-Scripting Guide:

http://www.linuxdoc.org/LDP/abs/html/index.html

Last edited by zmedico; 03-31-2002 at 05:22 PM.
 
Old 03-31-2002, 06:20 PM   #3
The Grepper
LQ Newbie
 
Registered: Mar 2002
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks, I took a look at the page and found something called dirname, which is the exact opposite of basename, and it worrks if I execute it on one line, but I would like to use it with find

find $x -name "*.$2"

where $x is my directory, and $2 are all the file extensions, it loops through any amount of command likes, so $2 is always changing

thanks again
 
Old 03-31-2002, 06:35 PM   #4
The Grepper
LQ Newbie
 
Registered: Mar 2002
Posts: 9

Original Poster
Rep: Reputation: 0
actually dirname will not work with how i run my script
since i put
program /home/thegrepper/ cpp txt

but with dirname you need /home/thegrepper/cpp
so when i use dirname for program /home/thegrepper/ cpp txt
my dirname ends up being /home/

does anyone know how to use {var%/*} ?????????????
 
Old 04-19-2002, 02:17 PM   #5
zmedico
Member
 
Registered: Feb 2002
Location: Mission Viejo, California, USA
Distribution: Gentoo
Posts: 707

Rep: Reputation: 30
Darn, I guess no one can figure out what you mean by this: ${varname%/*} Where did you get that from anyways?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration