Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  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%/*}

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


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


as being the directories that contain cpp files


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
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
Senior Member
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

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


dirname "/pub/program/file1.c"


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 > Forums > Non-*NIX Forums > Programming

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

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