LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-29-2002, 09: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, 04:10 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

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

or

dirname "/pub/program/file1.c"
 
  


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



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 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Shell Scripting again yaadhav Linux - Newbie 8 08-04-2005 10:21 AM
shell scripting pcdebb Linux - Newbie 17 11-20-2003 03:49 PM
shell scripting markus1982 Linux - General 2 05-20-2003 07:42 AM

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

All times are GMT -5. The time now is 04:26 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