LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 02: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, 02:20 PM   #2
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 510

Rep: Reputation: 120Reputation: 120
$basepath undefined.
cd $base_path
 
Old 11-19-2014, 04:21 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,932

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
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 04:33 PM.
 
Old 11-20-2014, 12:40 AM   #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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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-03-2014 12:56 AM
Putting cc Compiler into $PATH Davethesnake Linux - Newbie 6 10-31-2010 06:08 PM
how to change extensions for many files in other directory path FahadOnline Linux - Newbie 6 07-17-2008 03:40 AM
Mozilla Directory Path Change: go_sooner Linux - Software 4 06-11-2005 02:21 AM
How to change the path of the current directory ? ndha Linux - General 7 12-03-2003 12:05 PM


All times are GMT -5. The time now is 04:45 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration