Using ".." to change directories in a ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using ".." to change directories in a ksh script
# 1  
Old 10-24-2012
Data Using ".." to change directories in a ksh script

I have an issue driving me bonkers. I have a ksh script that requires changing directories. If a argument "TEST" is passed in, this is a regression test execution of the script (as opposed to production execution). I have a directory entitled "TEST" that is located three directory locations ABOVE where the script resides.

If I determine my current path using pwd, I am able to retrieve the current directory. I then append the following path info to the value retrieve with pwd. For example:
mypath=`pwd`
echo "DBG - my path is: " $mypath


This displays /home/joec/dev/solution/tools/libsearch.

I then append the following to the $mypath variable:
rbase=$mypath/../../../lib/$test/profiles

Where $test is the value passed in on the command line.

The problem I am having is this. I perform a check to see if the argument being passed in exists as a directory. The if [[ -d $rbase ]]; then checks to see if the directory for the TEST directory $rbase exists. The problem I am encountering is that the script is not processing the ".." to move up the directory tree. As a result, even though the path for $rbase exists, the ksh script is returning the value that it doesnt and thus exits the script incorrectly.

Is there something that I am (subtly) missing?

Smilie
# 2  
Old 10-24-2012
since running on current working directory try:
Code:
rbase=../../../lib/$test/profiles

or try setting:
Code:
rbase=${PWD%/*/*/*}/lib/$test/profiles

# 3  
Old 10-24-2012
No dice...

The first method you suggested I already tried (that was attempt #1). The 2nd method you suggested resorted in the same error message.

I normally dont think I am stupid, but this issue is causing me to rethink that premise. Smilie
# 4  
Old 10-24-2012
Have you checked if it's is a permission problem for cd, maybe? The -d test could pass but cd will fail.
# 5  
Old 10-24-2012
Not a permissions issue

I own the directory(s) in question and they are all using 755 (rwxr-xr-x). It isnt even making it through the -d conditional. I can change directories to the test path, but the conditional is flailing and failing.

Last edited by joe cipale; 10-24-2012 at 03:26 PM.. Reason: to add further information
# 6  
Old 10-24-2012
Please post your entire script. We can't see enough to figure out what's going wrong here.
# 7  
Old 10-24-2012
code snippet

I can post a portion. It is basically proprietary corp code.

Code:
#------------------------------------------------------------------
# Parse the command-line args
#------------------------------------------------------------------

while getopts "s:g:v:q:" flag
    do
        case $flag in
        s) srp_path=$OPTARG
           print "base release        : " $test_path
           ;;
        g) grp_path=$OPTARG
           print "support release        : " $spt_path
           ;;
        v) vers=$OPTARG
           print "support version        : " $vers
           ;;
        q) prd_path=$OPTARG
           print "product path       : " $prd_path
           ;;
: )          echo "$0: $OPTARG option missing argument..."
           exit 2
           ;;
        [?]) print >&2 "Usage: "$USAGE
           exit 1
           ;;

        esac
    done
shift $OPTIND-1

#------------------------------------------------------------------
# Check the correctness of the cmd-line values
#------------------------------------------------------------------

mypath=`pwd`
echo "DBG - my path is: " $mypath

#rbase=../../../lib/$test/profiles
#rbase=$mypath/../../../lib/$test/profiles
rbase=${PWD%/*/*/*}/lib/$test/profiles

# debug 
cd $rbase
rpath=`pwd` 
print "DBG - current path is: " $rpath

tbase=$tbase/$test
#rbase=$rbase/$test

print "DBG - Base path is: " $tbase
print "DBG - Regression path is: " $rbase

if [[ -d $tbase ]]; then
    # search paths
    test_path=$base/SOLUTION/$test/profiles
    print "DBG - path is: $test_path
elif [[ -d $rbase ]]; then
    # regression search paths
    #test_path=$rbase
    print "DBG - test path is: $rbase
else
print "The specified path does not exist..."
    exit 1
fi

The commented out bits of code are methods I have attempted and I would like to keep track of them for now.

Thanks folks.

Last edited by Corona688; 10-24-2012 at 04:17 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

How to fix this "Input is not UTF-8" while executing ksh script?

Hi, I have an automated script which have set of sqls but when i am trying to execute the automated script by using nohup command, it is throwing an error like "Input is not UTF-8" . And when i digged in to it, i am getting some "Â" character in the shell script. How to avoid this!? Thanks. (1 Reply)
Discussion started by: Samah
1 Replies

3. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

4. Shell Programming and Scripting

Awk,sed : change every 2nd field ":" to "|"

Hi Experts, I have a string with colon delimited, want 2nd colon to be changed to a pipe. data: 101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3: I am trying with sed, but can change only 1 occurance: echo "101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3:" | sed 's/:/|/2'... (5 Replies)
Discussion started by: rveri
5 Replies

5. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

6. Shell Programming and Scripting

Help to change the file with "sed" and "awk"

Hi experts I want your help to change the file format to my wanted version, please give me a hand thanks $cat file install pass make os pass make build kernel failed usb storage pass chane to | *install* | *make os* | *make build kernel* | *usb storage* | | pass | pass... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

7. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, I´ve already searched the forum but can´t find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

8. Shell Programming and Scripting

Ksh script function, how to "EXIT 2" without killing the current process?

Hi, Using AIX 5.3 and Ksh. />ls -al /usr/bin/ksh -r-xr-xr-x 5 bin bin 237420 Apr 10 2007 /usr/bin/ksh /> I recently started working for a new employer. I have written UNIX K-Shell scripts for many years and have never had this particular issue before. Its perplexing me. I have... (2 Replies)
Discussion started by: troym72
2 Replies

9. HP-UX

script running with "ksh" dumping core but not with "sh"

Hi, I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone. And its not dumping core if we run the script using "/bin/sh" instead of "ksh" Can some body please help me how to resolve this issue. ... (9 Replies)
Discussion started by: simhe02
9 Replies

10. Shell Programming and Scripting

ksh script as a login shell return "no controlling terminal"

I have created a ksh shell script and used it as a login shell for a user. </etc/passwd> lramirev:x:111:200:Luis:/export/home/menush:/usr/local/menush/menush My shell script is like this: </usr/local/menush/menush> #!/bin/ksh # if ] then . $HOME/.profile fi ... (8 Replies)
Discussion started by: lramirev
8 Replies
Login or Register to Ask a Question