Directory path shortening ????


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Directory path shortening ????
# 1  
Old 08-12-2010
Question Directory path shortening ????

As it was a new topic i started a new thread.

There are different Directories under
Code:
"$HOME/rsh/Desktop/at/bin/bellhop/ and $HOME/rsh/Desktop/at/examples/"

i want to perform some operation like cp or mv

Is it possible to do

Code:
R=$HOME/rsh/Desktop/at/bin/bellhop/
P=$HOME/rsh/Desktop/at/examples/
S=$HOME/rsh/Desktop/at/results

(assuming there is a directory 'x' under bellhop/x/file1 and similarly 'y' under /examples/y/file2)

cat  $R/x/file1 $P/y/file2 >$S/xy/file3

as i will be executing several commands of this fashion, i would try to avoid writing such big lines, is there an alternative way to achieve this.
# 2  
Old 08-12-2010
The way you've got it will actually work. However I'd change it just a little bit:

Code:
R="${HOME}/rsh/Desktop/at/bin/bellhop/"
P="${HOME}/rsh/Desktop/at/examples/"
S=${HOME}/rsh/Desktop/at/results"

cat  "${R}/x/file1" "${P}/y/file2" > "${S}/xy/file3"

The double quotes let it properly handle directory names containing spaces, which might otherwise be split into multiple arguments unexpectedly. The brackets around the variables let it identify variables in otherwise-ambiguous situations like $R_not_a_variable.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

Shortening a awk command

The purpose of the below is to grab the 9th field of the data in "$epochtimeframe". and then translate that data (which is an epoch time), into a human readable form. echo $epochtimeframe | awk -F"--" '{print $9}' | awk -F"," '{print $2}' | perl -pe 's/(\d+)/localtime($1)/e' i'm sure many... (10 Replies)
Discussion started by: SkySmart
10 Replies

6. Shell Programming and Scripting

file name shortening for multiple directories

there was a post previously about this from around 2010 but i was unable to get the suggested scripts there to work. the following code works for me when it's saved inside the directory of files whose names i want to shorten, but i would like to be able to store it in a file with a list of ... (4 Replies)
Discussion started by: giseismology
4 Replies

7. 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

8. 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

9. 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

10. Shell Programming and Scripting

Shortening Numbers

Hi, I'm using ksh and I'm trying to shorten a column of figures. For example, I'd like to turn: 3456789.9876 to 89.98 567.4956 to 67.49 4669493932.34564 to 32.34 ... so the input figure will vary in length, I'm not worried about rounding, I just want the two... (6 Replies)
Discussion started by: Jonny2Vests
6 Replies
Login or Register to Ask a Question