$dirname ??????


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers $dirname ??????
# 1  
Old 09-14-2011
$dirname ??????

Hi, okay, the following command was given to me in a script, but it's not working and there's little to no help on dirname. What is wrong with the following line? I'm just trying to save the current directory to use later in subsequent scripts.
MYAPPDIR=$(dirname $(dirname $0))

Thanks.
# 2  
Old 09-14-2011
$0 is the path and name of the current running script. So if you called it as /full/path/to/app it's that, and if you called it as ./app, it's only that.
Now the first (inner) dirname removes the name of the application, so it's only /full/path/to or . anymore.
With the second dirname, you're shortening it even more, becoming /full/path and . respectively.

What you probably need is a simple MYAPPDIR=$( pwd )
# 3  
Old 09-14-2011
Super helpful. Thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using dirname on a file before uniq

Hello, I have a list of files generated like this: find dir -type f > file_list I want to get a list of just the unique directories. I can't create a temporary file. So the idea is to do a working equivalent to this: cat file_list | dirname | uniq But of course that doesn't... (4 Replies)
Discussion started by: brsett
4 Replies

2. Shell Programming and Scripting

help with dirname

We are using #!/bin/sh From a command line this command returns the correct list of files (without going into any subdirectories) find /vol.prod/saptrans/common/test/pa/* -prune -type f -print We have a script which takes the same path as $1 (without the * ) ... (2 Replies)
Discussion started by: 15a0
2 Replies

3. Programming

basename and dirname changes the value of argument???

Hi I faced with some interesting behavior of basename and dirname functions from libgen.h: they changes the value of argument! Here is the declaration: char *basename(char *); char *dirname(char *);It makes some tiresome to use them... I am new to C and maybe I do something wrong, but to... (4 Replies)
Discussion started by: Sapfeer
4 Replies

4. Shell Programming and Scripting

find & dirname:problems with white spaces in Directories

Hi all, my problem: (little extract from my bash-script) I want to move each file (.mov) from one directory (and many Subdirectories) to another directory (only one); after moving i want to create hardlinks to the old directories. Thatīs no problem, but now: source-directories... (4 Replies)
Discussion started by: tubian
4 Replies

5. Shell Programming and Scripting

dirname, save cut portion to variable, clean up

Hi guys, last cry for help for today. I appreciate the help so far. ok so I have a program that dumps a path into my script as a variable ($1) This path is an example /home/xbmc/sab_downloads/video/tv/grey's anatomy/season 3 So in order to search thetvdb.com for a show, I need to extract... (6 Replies)
Discussion started by: tret
6 Replies

6. Shell Programming and Scripting

strip hostname from dirname?

I need to get the full path of a file minus the hostname... anyone have an easy way to do this? What I have is: //ourhostname/ourfullpath/filename What I need is: /ourfullpath/filename hostname evaluates to 'ourhostname' dirname evaluates to '//ourhostname/ourfullpath' basename... (2 Replies)
Discussion started by: tink
2 Replies

7. Shell Programming and Scripting

Setting basename and dirname variable to simply script.

Hello all, Can somebody explain to me how set up a basename and dirname variable to simplify this script. I currently have a 'infile' with the contents of FTTPDataPVC_ & BaaisDSLFeed. I need to add a basename and or dirname variable so that any additions can be made through the infile and not... (1 Reply)
Discussion started by: liketheshell
1 Replies
Login or Register to Ask a Question