Richard Rublev Richard Rublev - 7 months ago 13
Bash Question

Why is my cd not working in bash?

I have written small bash to automate my code

#!/bin/bash

jhome () {
cd /home/milenko/OCCAM2DMT_V3.0/cifort
}
./Occam2D start.txt


The exe file is Occam2d and input file is start.txt.
When I run my script I got

bash a.sh
a.sh: line 6: ./Occam2D: No such file or directory


Why?

Answer

With @anubhava's comment:

#!/bin/bash

jhome () {
  cd /home/milenko/OCCAM2DMT_V3.0/cifort
}

# call your function to change directory
# and only if cd was successful run ./Occam2D
jhome && ./Occam2D start.txt