LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2014, 01:15 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
putting a path into a varaible and change directory


I have this script that just unzips a few files.
I have labeled this directory in the "basename"
name space. Which is great becuase I don't have to
write out the whole thing in the line every time I
reference the path. However the script does not change to the
directory. The "cd to $basename" does not work.
the script does not switch to the basename direcotry after it is done .
Code:
   #!/bin/bash
    wrapper_date=$(/bin/date +%Y%m%d)

    base_path="/sbcimp/dyn/data/EVT_RESEARCH1/engine_logs/qgen/"
    file1="/casper-process-1.log"
    file3="/casper-process-3.log"


    gunzip "$base_path$wrapper_date$file1.gz"
    gunzip "$base_path$wrapper_date$file3.gz"
    #does this not go to the next command unless the gzip is done.
    cd $basepath
    pwd
 
Old 11-19-2014, 01:20 PM   #2
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
$basepath undefined.
cd $base_path
 
Old 11-19-2014, 03:21 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Could be a typo but the shell does not inherit a program's environment (actually it is a child process) even though you change directories from within the script once it exists your back where you started.

Last edited by michaelk; 11-19-2014 at 03:33 PM.
 
Old 11-19-2014, 11:40 PM   #4
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
Or you can use pushd/popd to change directories and return to the stored directories when you're done.

Cheers
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
block the users to change directory path in ftp sudheer1243 Linux - Newbie 2 07-02-2014 11:56 PM
Putting cc Compiler into $PATH Davethesnake Linux - Newbie 6 10-31-2010 05:08 PM
how to change extensions for many files in other directory path FahadOnline Linux - Newbie 6 07-17-2008 02:40 AM
Mozilla Directory Path Change: go_sooner Linux - Software 4 06-11-2005 01:21 AM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 11:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration