Get up one directory of location as variable

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Get up one directory of location as variable
# 1  
Old 03-28-2012
Get up one directory of location as variable

May i know how can i pass up one of a location to a variable in script file with command in stead of hardcode?

saying in my script file:

Code:
maindir = "/opt/xSystem/config"
upOneDir = ?????
echo $upOneDir

I have to use command to pass "/opt/xSystem"
to variable upOneDir.

Please advise..

many thanks!
# 2  
Old 03-28-2012
Code:
echo $mainder |awk -F/ '{gsub($NF,"");print}' |sed 's/.$//'

This User Gave Thanks to ningy For This Post:
# 3  
Old 03-28-2012
hello Ningy,

thanks for your prompt reply.

I have tested your advice but still unable to get the thing work.

Please advice again.
Thank you

---------- Post updated at 04:34 AM ---------- Previous update was at 03:39 AM ----------

and why below only works for pwd.. but not other location..

Code:
dir1=$PWD
echo $dir1

higher_dir=$(cd ..
pwd)
echo higher_dir

this doesn't work when i replace the $PWD with "/opt/xSystem"

please advice..

Many thanks!
# 4  
Old 03-28-2012
what output did u get when u ran my command above coz it worked for me..
# 5  
Old 03-28-2012
What shell do you use? In case of bash there are some nice string manipulation features:
Code:
maindir=/opt/xSystem/config
upOneDir=${maindir%/*}
echo $upOneDir
/opt/xSystem

This User Gave Thanks to cero For This Post:
# 6  
Old 03-29-2012
hello ningy..

it shows the blank.. hmm i did edit "maindir" from your code

thanks yea

---------- Post updated at 12:22 PM ---------- Previous update was at 12:21 PM ----------

hi cero,
thanks! it is working.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching the value of a specific attribute among xmls files from a particular directory location

Hi Folks , I have the different xml files at the following directory `/opt/app/rty/servers/tr/current/ops/config` Let's say there are three files named abc.xml bv.xml ert.xml Now inside these xml there can be many tags as like shown below <bean id="sdrt"... (6 Replies)
Discussion started by: unclesamm
6 Replies

2. Post Here to Contact Site Administrators and Moderators

How to count successfully copy files source to target location with check directory in Linux?

Hi guys...please any one help me .... how to copy files from source to target location if 5 files copied successfully out of 10 files then implement success=10 and if remaining 5 files not copied successfully then count error=5 how to implement this condition with in loop i need code linux... (0 Replies)
Discussion started by: sravanreddy
0 Replies

3. UNIX for Dummies Questions & Answers

Find the location of particular file and directory

hi all, i am new to UNIX environment. i have a file and directory with same name, i don't know the location I want to find location of that file and directory. please suggest a solution. (5 Replies)
Discussion started by: mahesh1987
5 Replies

4. Shell Programming and Scripting

How to find a existing file location and directory location in Solaris box?

Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box (1 Reply)
Discussion started by: buzzme
1 Replies

5. Shell Programming and Scripting

using find to go directly into a directory location

is there any other useful command to go into a specific directory and not go into its subdirectories that operates similar to find.? (it will return the full pathname?) or is there any way to make find not go into the subdirectories of the specified directory? This is on ksh as well. (3 Replies)
Discussion started by: bjhum33
3 Replies

6. UNIX for Dummies Questions & Answers

auto change filemanager folder colors dependent on location in directory hierarchy

Hello, Is it possible to make a file manager use different "colored folders" when browsing specific directories? For example, if I open a gnome file manager and browse my windows share at, smb://192.168.1.101/z/ , can I make those folders appear green? And when I open another instance of... (0 Replies)
Discussion started by: bz43
0 Replies

7. UNIX for Dummies Questions & Answers

write a directory location

Hi, Just want to be sure that if I write a directory like: /documents/script.pl is the same as to write: /documents//script.pl Thanks in advance (1 Reply)
Discussion started by: fadista
1 Replies

8. UNIX for Dummies Questions & Answers

Copy directory from one location to other

Hi All, I am newbie for Unix. I want to copy a directory from one location to other. Can any one help me by providing the command to do following task. thanks in advance, Rakesh (2 Replies)
Discussion started by: rakeshvthu
2 Replies

9. Shell Programming and Scripting

Home Directory Location Code

Hello All, I am a teacher at a local high school, and we have put together a small computer and loaded a linux distro onto it for the students to experiment with, because 20 children share the computer, it is hard to keep track of there home directorys, i was wondering if i could find a script... (10 Replies)
Discussion started by: hks_turbokits
10 Replies
Login or Register to Ask a Question