0

My script

#!/bin/bash

for i in *_TEx_*.dat;
do
    file1=$i
done

for i in *_TEy_*.dat;
do
    file2=$i
done

echo file1="$file1"
echo file2="$file2"

awk '$0+0 == $0 { printf "%.3f\n", $0 / .05 }' "$file1" > ex65536.dat
awk '$0+0 == $0 { printf "%.3f\n", $0 / .05 }' "$file2" > ey65536.dat

mv *.dat /home/milenko/birrp

mycd() {
    cd /home/milenko/birrp
}

mycd

But

milenko@milenko-HP-Compaq-6830s:~/procmt$ pwd
/home/milenko/procmt

What is wrong with my instructions to change the working directory?

Richard Rublev
  • 5,592
  • 9
  • 42
  • 87
  • this happens because you are moving to another directory in the subshell that runs the script. Once it finishes, you are back in the main shell, where no `cd` was performed. – fedorqui 'SO stop harming' Aug 18 '16 at 14:02
  • the wd is changed for the sub-shell executing the script, not your interactive shell that spawned the sub-shell – Tom Regner Aug 18 '16 at 14:03

1 Answers1

1

try

...
mycd() {
    cd /home/milenko/birrp
    exec /bin/bash
}

mycd

or run your script as below;

. ./yourscript.sh
Mustafa DOGRU
  • 3,704
  • 1
  • 11
  • 19