The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to change parent shell's variables? pankai Shell Programming and Scripting 1 01-17-2008 04:32 PM
Script look for file ,sort and copy to other direcotry reddi22 Shell Programming and Scripting 0 01-17-2008 03:56 PM
Awk and Variables deepak4you Shell Programming and Scripting 4 11-15-2007 09:18 AM
Return to the Home direcotry shoeb_syed UNIX for Dummies Questions & Answers 4 02-17-2006 01:47 AM
Can't delete a direcotry oradbus UNIX for Advanced & Expert Users 0 05-31-2005 04:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2004
jsalz638 jsalz638 is offline
Registered User
  
 

Join Date: Jul 2004
Posts: 6
Question can you change direcotry using variables?

is this allowed?

cd ../$var


inside of a for loop?

I want to be able to go into a new folder in the same directory with each iteration of the loop. I want $var to change to the folder number I am trying to get into.
  #2 (permalink)  
Old 07-02-2004
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,122
Yes.
  #3 (permalink)  
Old 07-02-2004
hem hem is offline
Registered User
  
 

Join Date: Jun 2004
Location: Edina, MN
Posts: 1
Yes. It is allowed. You can change directories using variables. Below is sample code to do that in which directories has the list of directories that needs to be accessed to get information.

for var in `cat directories`
do
cd ../$var
pwd
done
  #4 (permalink)  
Old 07-04-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
One point here - rather than using cat, I'd do

Code:
while read var 
do 
   cd ../$var
   #do something
done < directory_list
This saves us an unneeded "cat"

Just my two pence

Ta,
ZB
  #5 (permalink)  
Old 07-06-2004
jsalz638 jsalz638 is offline
Registered User
  
 

Join Date: Jul 2004
Posts: 6
Thanks! Getting closer...do any of you guys know a good reference website for syntax?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0