Skip to content
Advertisement

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?

Advertisement

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
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement