0

I have just written this function in a Shell Script:

clone_and_dev() {
  REPO=$1
  echo
  echo "Beginning process for the $REPO repository..."
  git clone git@github.com:keyfer/$REPO.git
  cd "$REPO"
}

The problem lies with that the cd command does not seem to work. I'm wondering if there is a way to make this work.

Thanks!

JPBlanc
  • 63,198
  • 12
  • 118
  • 155
Keyfer Mathewson
  • 935
  • 2
  • 15
  • 26
  • 1
    Is this contained in a script and you run the script like `./script` or `bash script`? If yes, `cd` has no effect because it happens in a subshell, which cannot affect the parent shell. If however "no effect" is meant for a function call within the same script, then I'm not sure. – Benjamin W. Feb 01 '17 at 04:11
  • @benjamin This is a executable file in ~/bin which then call by just running `clonescipt` in terminal. There are other parts of this script though, which call the function and pass param. – Keyfer Mathewson Feb 01 '17 at 04:20
  • Then it can't change the directory for you, see for example [this question](http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script?noredirect=1&lq=1) and [BashFAQ 60](http://mywiki.wooledge.org/BashFAQ/060). – Benjamin W. Feb 01 '17 at 04:24
  • I remove PowerShell, it's not envolved here. – JPBlanc Feb 01 '17 at 04:29
  • 1
    Possible duplicate of [Why doesn't "cd" work in a bash shell script?](http://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-bash-shell-script) – tripleee Feb 01 '17 at 05:08

1 Answers1

0

You need to add a start cmd /k or start cmd /k "place commands for new window here" see:

clone_and_dev() {
  REPO=$1
  echo
  echo "Beginning process for the $REPO repository..."
  git clone git@github.com:keyfer/$REPO.git
  cd "$REPO"
  start cmd /k
}
Will
  • 118
  • 1
  • 9