Richard Rublev Richard Rublev - 3 months ago 18
Linux Question

Why working directory has not been changed with my script?

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?

Answer

try

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

mycd

or run your script as below;

. ./yourscript.sh