LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   putting a path into a varaible and change directory (https://www.linuxquestions.org/questions/linux-newbie-8/putting-a-path-into-a-varaible-and-change-directory-4175525906/)

casperdaghost 11-19-2014 01:15 PM

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


Teufel 11-19-2014 01:20 PM

$basepath undefined.
cd $base_path

michaelk 11-19-2014 03:21 PM

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.

gdejonge 11-19-2014 11:40 PM

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

Cheers


All times are GMT -5. The time now is 11:07 PM.