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
# 8  
Old 10-24-2012
If you run it under strace/truss/tusc, you can see it traverse every directory and exactly what path is in error. It's very educational! Remember that .. is a real directory entry (same for .), so it should work just as well as any entry name. Not like '~' and '~username' ! I often miscount the ../ by one!
# 9  
Old 11-01-2012
If you're using bash or ksh, you can use pushd & popd instead of cd.

Code:
pushd dirname >/dev/null 2>/dev/null

...

popd >/dev/null 2>/dev/null # puts you back where you started

# 10  
Old 11-01-2012
You can "cd" anc "cd -", too, but I prefer to never leave $HOME except in ():
Code:
$ ( cd x/y/z
for f in *
do
 . . .
done
)

# 11  
Old 11-01-2012
pushd/popd are not valid

pushd/popd are not supported in ksh/bash/bourne shell.

I resolved the issue and all is good. Just been too busy to respond. Thanks for all the ideas.

Joe
# 12  
Old 11-01-2012
Quote:
Originally Posted by joe cipale
pushd/popd are not supported in ksh/bash/bourne shell.
They are not all the same.

KSH supports it.

BASH supports it.

Generic bourne does not.
# 13  
Old 11-01-2012
not on Solaris 10/11

I just performed a check and pushd/popd only exists (at least on my install) in csh. It may be an add-on package that our IT goblins do not install.

I wish pushd/popd DID exist on my install, that is for certain.
# 14  
Old 11-01-2012
Quote:
Originally Posted by joe cipale
I just performed a check and pushd/popd only exists (at least on my install) in csh. It may be an add-on package that our IT goblins do not install.
It's not an add-on, it's a shell built-in and has to be a shell builtin to work, just like cd. A cd binary would be pretty useless (your cd program succeeds in changing directory -- but your shell remains where it is).*

You can write a function to emulate it but it would be annoying to do and imperfect, since some of the side effects (keeping the directory open) couldn't be duplicated.

KSH93 has it, pretty sure. KSH88 and PDKSH may not. BASH definitely has it.

* If you want to be picky, a cd binary does have some uses, but none of them are what you'd usually want cd for.
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