LinuxQuestions.org
Visit Jeremy's Blog.
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-29-2002, 10:53 AM   #1
The Grepper
LQ Newbie
 
Registered: Mar 2002
Posts: 9

Rep: Reputation: 0
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
 
Old 03-29-2002, 05:10 PM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
You can try to use dirname:
Code:
echo "/pub/program/file1.c" | xargs dirname

or

dirname "/pub/program/file1.c"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM
Shell Scripting again yaadhav Linux - Newbie 8 08-04-2005 11:21 AM
shell scripting pcdebb Linux - Newbie 17 11-20-2003 04:49 PM
shell scripting markus1982 Linux - General 2 05-20-2003 08:42 AM


All times are GMT -5. The time now is 09:09 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration