Sponsored Content
Top Forums Shell Programming and Scripting How to get last directory path in script Post 302669129 by vel4ever on Tuesday 10th of July 2012 12:42:36 PM
Old 07-10-2012
Below is the error which i got when using dirname

Code:
dirname: missing operand
Try `dirname --help' for more information.

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to get directory name from its path?

If I the path to a directory, what command can I use to return the actual name of that directory. test=`pwd`/folder1 > $test folder1 I'd rather avoid anything with regular expressions. Any ideas? (1 Reply)
Discussion started by: ordano
1 Replies

2. Shell Programming and Scripting

absolute path for a script ran with relative path

I have a script in which i want to print absolute path of the same script irrespective of path from where i run script. I am using test.sh: echo "pwd : `pwd`" echo "script name: $0" echo "dirname: `dirname $0`" when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Discussion started by: rss67
10 Replies

3. Shell Programming and Scripting

Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. $home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?... (7 Replies)
Discussion started by: royzlife
7 Replies

4. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

5. Shell Programming and Scripting

Error when using certain directory path

Hi, I am using the following code to check if directory is empty: if ; then echo "There is no files in the input" sleep 60 fi And indir path is: /CH_ROOT/PRD/MAIN/INPUT/SDNTL/Interconnect Only when I am using the above path I get an error "too many arguments". I tried with 10... (4 Replies)
Discussion started by: apenkov
4 Replies

6. Shell Programming and Scripting

Keep last directory from path

Hello, I am looking for a command that will give me the last directory name from a path ex 1 : /dir1/dir/2/dir3/ output needed dir3 ex 2 : /dir1/dir/2/dir3/dir4/ output needed dir4 (1 Reply)
Discussion started by: Aswex
1 Replies

7. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

8. Shell Programming and Scripting

Pass File name and Directory Path through command to python script

I'm writing python script to get the file-names in the current directory and file sizes .I'm able to get file list and their sizes but unable to pass them through command line. I want to use this script to execute on other directory and pass directory path with file name through command line. Any... (1 Reply)
Discussion started by: etldeveloper
1 Replies

9. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

10. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies
dirname(3C)						   Standard C Library Functions 					       dirname(3C)

NAME
dirname - report the parent directory name of a file path name SYNOPSIS
#include <libgen.h> char *dirname(char *path); DESCRIPTION
The dirname() function takes a pointer to a character string that contains a pathname, and returns a pointer to a string that is a pathname of the parent directory of that file. Trailing '/' characters in the path are not counted as part of the path. If path does not contain a '/', then dirname() returns a pointer to the string "." . If path is a null pointer or points to an empty string, dirname() returns a pointer to the string "." . RETURN VALUES
The dirname() function returns a pointer to a string that is the parent directory of path. If path is a null pointer or points to an empty string, a pointer to a string "." is returned. ERRORS
No errors are defined. EXAMPLES
Example 1: Changing the Current Directory to the Parent Directory. The following code fragment reads a pathname, changes the current working directory to the parent directory of the named file (see chdir(2)), and opens the file. char path[[MAXPATHLEN], *pathcopy; int fd; fgets(path, MAXPATHLEN, stdin); pathcopy = strdup(path); chdir(dirname(pathcopy)); fd = open(basename(path), O_RDONLY); Example 2: Sample Input and Output Strings for dirname(). In the following table, the input string is the value pointed to by path, and the output string is the return value of the dirname() func- tion. +-----------------------------+-----------------------------+ | Input String | Output String | +-----------------------------+-----------------------------+ |"/usr/lib"" |"/usr" | +-----------------------------+-----------------------------+ |"/usr/" |"/" | +-----------------------------+-----------------------------+ |"usr" |"/" | +-----------------------------+-----------------------------+ |"/" |"/" | +-----------------------------+-----------------------------+ |"." |"." | +-----------------------------+-----------------------------+ |".." |"." | +-----------------------------+-----------------------------+ USAGE
The dirname() function modifies the string pointed to by path. The dirname() and basename(3C) functions together yield a complete pathname. The expression dirname(path) obtains the pathname of the directory where basename(path) is found. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
basename(1), chdir(2), basename(3C), attributes(5), standards(5) SunOS 5.10 18 Mar 2002 dirname(3C)
All times are GMT -4. The time now is 09:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy