Sponsored Content
Top Forums Shell Programming and Scripting getting the path part of an argument Post 48950 by druuna on Monday 22nd of March 2004 12:27:06 PM
Old 03-22-2004
This works:

Code:
#!/bin/bash

INPUT="$1"

echo "Original : "${INPUT}
echo ""
echo "Without path : "${INPUT##/*/}
echo ""
echo "Path only : "${INPUT%/*}

$ cut-it /a/b/c/d/e/somefile
Original : /a/b/c/d/e/somefile

Without path : somefile

Path only : /a/b/c/d/e


Only works if a path is given with the filename....... But you might be able to work around that.

Should work for bash and ksh, check manpage (Parameter Expansion, near the bottom of the paragraph) for a more detailed explanation.

Hope it helps anyway Smilie
druuna
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Maximum length of a path given as an argument to a shell script

hi, I am using solaris10. I have to write a bourne shell script, which copies files for the said destination path which is passed as an argument to the script. it looks like this myscript.sh /var/test -->destination path now i would like to know what is the maximum length i can... (3 Replies)
Discussion started by: raghu.amilineni
3 Replies

2. Shell Programming and Scripting

retrieve part of file path

Hi I am trying to use sed to retrieve part of my html file's path. I am having a hard time getting what I want. Could someone give me some help? I want to retrieve the section after html and before the file name For example if I have the following, ... (3 Replies)
Discussion started by: tiger66
3 Replies

3. Shell Programming and Scripting

regex to select last part of a path

Hi all, I am learning the use of regular expression and I would like to know which regex can be used to select only the last part of a directory path name. Something like: /dir1/dir2/dir2 and I want to select the last /dir2 where dir2 can be any kind of string. Thanks a lot for your help.... (7 Replies)
Discussion started by: elric
7 Replies

4. Shell Programming and Scripting

taking a part of string from a given path

Hi I have two path as follows system/console/bin/code/sample/testfile.txt system/console/bin/database/files/new/dbfile.txt I need the output as code/sample in first case database/files/new in second case That is I am omitting system/console/bin and the filename(s) in both... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

5. UNIX for Advanced & Expert Users

How do i use vi to substitute an expression that is part of a path?

Let say I have /home/user1/bin/ and i want it to be /root/bin I tried : s/\/home\/user1/user2/ but it can't find the pattern user1. I tried: s/*\/home\/user1*/user2/ as well same result many thanks (4 Replies)
Discussion started by: c00lsnoopy
4 Replies

6. UNIX for Advanced & Expert Users

Passing full path as argument when it contains variable strings

Hi, In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles". This is my code : ... (0 Replies)
Discussion started by: KidD312
0 Replies

7. Programming

Passing full path as argument when it contains variable strings

Hi, In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles". This is my code : ... (1 Reply)
Discussion started by: KidD312
1 Replies

8. Shell Programming and Scripting

Pass argument in script to run specific part in that

Hello Friends, I need you help ! I have a scripts names runsteps.sh which contains command to run bunch of commands for each application you want to install " Oracle " Jboss" etc echo " Which app you want to install Jboss" ? Yes or no? read ans depending on Yes or not it goes inside... (3 Replies)
Discussion started by: saurabh84g
3 Replies

9. Shell Programming and Scripting

Identify full path in argument

I have a small script to send copies of files to another computer used for tests but in the same location:pwd=`pwd` for i in "$@" do echo "rcp -p $i comp-2:$pwd/$i" rcp -p $i comp-2:$pwd/$i echo "Finished with $i" doneIs there a way I can check the parameter to see if it is a full... (5 Replies)
Discussion started by: wbport
5 Replies

10. UNIX for Advanced & Expert Users

A way to print only part of directory path

Hi, So I struggled to find a solution to the following problem: I want to make sed print only part of multiple different paths. So lets say we have /path/path1/path2/logs/bla/blabla /path/path1/path2/path3/logs/yadda/yadda/yadda Can someone suggest a way to make sed or other... (5 Replies)
Discussion started by: dampio
5 Replies
FTP_MDTM(3)								 1							       FTP_MDTM(3)

ftp_mdtm - Returns the last modified time of the given file

SYNOPSIS
int ftp_mdtm (resource $ftp_stream, string $remote_file) DESCRIPTION
ftp_mdtm(3) gets the last modified time for a remote file. Note Not all servers support this feature! Note ftp_mdtm(3) does not work with directories. PARAMETERS
o $ftp_stream - The link identifier of the FTP connection. o $remote_file - The file from which to extract the last modification time. RETURN VALUES
Returns the last modified time as a Unix timestamp on success, or -1 on error. EXAMPLES
Example #1 ftp_mdtm(3) example <?php $file = 'somefile.txt'; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // get the last modified time $buff = ftp_mdtm($conn_id, $file); if ($buff != -1) { // somefile.txt was last modified on: March 26 2003 14:16:41. echo "$file was last modified on : " . date("F d Y H:i:s.", $buff); } else { echo "Couldn't get mdtime"; } // close the connection ftp_close($conn_id); ?> PHP Documentation Group FTP_MDTM(3)
All times are GMT -4. The time now is 11:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy